题解:CF1977D XORificator
题意
给定一个
思路
对于矩阵中的每一个数字,可以考虑如果它是当前列唯一一个
具体地,我们可以枚举每一列,先枚举一遍每一个数字,记录出将这一列全变成
代码
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e5 + 5;
const int mod = 25364761;
ll n, m, p[N];
mt19937_64 gen(time(0));
struct tp{
ll x, y, cnt;
};
map<ll, tp> mp;
void solve(){
cin >> n >> m;
vector<vector<char>> a(n + 1, vector<char> (m + 1, ' '));
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> a[i][j];
}
}
p[0] = 0;
for(int i = 1; i <= n; i++){
p[i] = gen();
}
mp.clear();
ll ans = 0, po = 0;
for(int i = 1; i <= m; i++){
ll op = 0;
for(int j = 1; j <= n; j++){
if(a[j][i] == '1'){
op ^= p[j];
}
}
for(int j = 1; j <= n; j++){
op ^= p[j - 1];
op ^= p[j];
mp[op] = {j, i, mp[op].cnt + 1};
if(mp[op].cnt > ans){
ans = mp[op].cnt;
po = op;
}
}
}
cout << ans << '\n';
tp it = mp[po];
for(int i = 1; i <= n; i++){
cout << ((i == it.x && a[i][it.y] == '0') || (i != it.x && a[i][it.y] == '1') ? 1 : 0);
}
cout << '\n';
}
int main(){
ios::sync_with_stdio(false), cin.tie(0);
int T;
cin >> T;
while(T--){
solve();
}
return 0;
}