ICPC2020济南A Matrix Equation
写在前面
大概是高中退役之后第一次写写题解,当然要从基础写起,因为变得更菜了,所以只能写写更水的题目了
题目链接
题解
\(A \times B = C⊙B\)
\[B_{ij} \times C_{ij}=\sum_{k = 1}^{n}A_{ik} B_{kj} (mod 2)
\]
对于每个\(j\)有
\[[i = 1,2,...n]\sum_{k = 1}^n (A_{ik} [k = i]xorC_{i})B_i
\]
对于每个\(j\)都有\(n * n\)的异或方程组,求自由元设为\(k_j\)得到方程组的解的个数为\(2^{k_{j}}\)
每个\(j\)独立于是有\(ans = \prod_{j=1}^n2^{k_{j}}\)
复杂度\(n^4/32\)
代码
#include<cmath>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a = b;a <= c;++ a)
using namespace std;
#define gc getchar()
#define pc putchar
inline int read() {
int x = 0;
char c = gc;
while(c < '0' || c > '9') c = gc;
while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = gc;
return x;
}
const int maxn = 207;
#define LL long long
const int mod = 998244353;
int n;
int A[207][207];
int B[207][207];
int type[maxn];
LL qpow(int k) {
if(k <= 0) return 1;
LL ret = 1,tmp = 2;
for(;k;k >>= 1) {
if(k & 1) ret *= tmp,ret %= mod;
tmp *= tmp,tmp %= mod;
}
return ret;
}
bitset<330>a[305];
LL guass(int equ,int var) {
int r,c,t;
for(r = c = 1;r <= equ && c <= var;++ r,++ c) {
for(t = r;t <= equ;++ t) if(a[t][c]) break;
if(t == equ + 1) {
-- r;continue;
} else swap(a[t],a[r]);
if(a[r][c] == 0) { r -- ;continue; }
for(int i = r + 1;i <= equ;++ i) if(a[i][c]) a[i] ^= a[r];
//for(int i = 1;i <= n;++ i) for(int k = 1;k <= n;++ k) cout<<a[i][k];puts("") ;
}
return qpow(var + 1 - r);
}
int main() {
n = read();
rep(i,1,n) rep(j,1,n) A[i][j] = read();
rep(i,1,n) rep(j,1,n) B[i][j] = read();
LL ans = 1;
for(int j = 1;j <= n;++ j) {
rep(i,1,n) rep(k,1,n) a[i][k] = A[i][k];
rep(i,1,n) a[i][i] = (A[i][i] ^ B[i][j]);
//rep(i,1,n) rep(k,1,n) cout<<a[i][k];puts("") ;
ans *= guass(n,n); ans %= mod;
}cout<< ans;
}
关于抄之前代码发现之前代码写错了竟调了一中午这件事。。。