QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#620029 | #7900. Gifts from Knowledge | qmqcbhc | WA | 4ms | 37112kb | C++20 | 1.7kb | 2024-10-07 16:21:49 | 2024-10-07 16:21:50 |
Judging History
answer
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const ll N=1e6+5;
const ll mod=1e9+7;
ll t,n,m;
string str[N];
ll a[2*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]=a[y]; //x以y为父
}
signed main()
{
fio();
cin >> t;
while(t--){
cin >> n >> m;
init_set(n);
for(int i=1; i<=m; i++){
vis[i].clear();
}
for(int i=1; i<=n; i++){
//str[i].clear();
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()==0 || vis[m-i+1].size()==0) continue;
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++){
ans%=mod;
ans*=2;
ans%=mod;
}
cout << ans%mod;
if(t!=1) cout << endl;
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 37112kb
input:
3 3 5 01100 10001 00010 2 1 1 1 2 3 001 001
output:
4 0 4
result:
wrong answer 3rd numbers differ - expected: '2', found: '4'