QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#619940 | #7900. Gifts from Knowledge | qmqcbhc | WA | 11ms | 100976kb | C++20 | 1.6kb | 2024-10-07 16:05:47 | 2024-10-07 16:05:48 |
Judging History
answer
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const ll N=3e6+5;
const ll mod=1e9+7;
ll t,n,m;
string str[N];
ll a[N];
vector<ll> vis[N];
void fio(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void init_set(int n){
for(int i=0; i<=2*n+5; i++){
a[i]=i;
}
}
int find_set(int x){
if(x != a[x]) a[x]=find_set(a[x]); //压缩路径
return a[x];
}
void merge_set(int x, int y){
x = find_set(x);
y = find_set(y);
if(x!=y) a[x]=y; //x以y为父
}
signed main()
{
fio();
cin >> t;
while(t--){
cin >> n >> m;
init_set(n);
for(int i=0; i<=m; i++){
vis[i].clear();
}
for(int i=1; i<=n; i++){
cin >> str[i];
}
//i是不翻,i+n翻
ll flag=0;
for(int i=1; i<=n; i++){
for(int j=0; j<m; j++){
if(str[i][j]=='1'){
vis[j+1].push_back(i);
}
}
}
for(int i=1; i<=m; i++){
//cout << vis[i].size() << endl;
if(vis[i].size()+vis[m-i+1].size()>2){
flag=1;
}
if(vis[i].size()==1){
merge_set(vis[i][0],vis[m-i+1][0]);
merge_set(vis[i][0]+n,vis[m-i+1][0]+n);
}
else if(vis[i].size()==2){
merge_set(vis[i][0]+n,vis[i][1]);
merge_set(vis[i][0],vis[i][1]+n);
}
}
for(int i=1; i<=n; i++){
if(find_set(i)==find_set(i+n)) flag=1;
}
if(flag){
cout << 0 << endl;
continue;
}
ll ans=1;
ll cc=0;
for(int i=1; i<=2*n; i++){
if(a[i]==i){
cc++;
}
}
cc/=2;
for(int i=1; i<=cc; i++){
cc--;
ans%=mod;
ans*=2;
ans%=mod;
}
cout << ans%mod << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 11ms
memory: 100976kb
input:
3 3 5 01100 10001 00010 2 1 1 1 2 3 001 001
output:
2 0 2
result:
wrong answer 1st numbers differ - expected: '4', found: '2'