QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#666558 | #7900. Gifts from Knowledge | nahida_qaq | WA | 3ms | 3788kb | C++23 | 1.9kb | 2024-10-22 19:03:16 | 2024-10-22 19:03:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+5,p=1e9+7;
int T;
int n,m;
char s[N];
vector <int> d[N];
vector <int> e[N];
int vis[N];
int ans;
int DFS(int u)
{
for(auto i:e[u])
{
int v = e[u][i];
if(vis[v]==vis[u]) return 0;
if(vis[v]) continue;
vis[v] = (vis[u]==1)?2:1;
if(!DFS(v)) return 0;
}
return 1;
}
int main() {
cin>>T;
while(T--) {
cin>>n>>m;
for(int i=1;i<=m;i++) d[i].clear();
for(int i=1;i<=2*n;i++) e[i].clear(), vis[i] = 0;
ans = 1;
for(int i=1;i<=n;i++) {
scanf("%s",s+1);
for(int j=1;j<=m;j++) if(s[j]=='1') d[j].push_back(i);
}
if(m&1) if(d[m/2+1].size()>1) { cout<<0<<endl; continue; }
bool duo = 0;
for(int i=1;i<=n;i++) {
e[i].push_back(i+n);
e[i+n].push_back(i);
}
for(int i=1;i<=m/2;i++) {
if(d[i].size()+d[m+1-i].size()>2) {duo = 1; break;}
if(d[i].size()+d[m+1-i].size()<2) continue;
if(d[i].size()==1) {
int u = d[i][0], v = d[m+1-i][0];
if(u==v) continue;
e[u].push_back(v+n);
e[v+n].push_back(u);
e[v].push_back(u+n);
e[u+n].push_back(v);
}
else {
int u,v;
if(d[i].size()) u = d[i][0], v = d[i][1];
else u = d[m+1-i][0], v = d[m+1-i][1];
e[u].push_back(v);
e[v].push_back(u);
e[u+n].push_back(v+n);
e[v+n].push_back(u+n);
}
}
if(duo) { cout<<0<<endl; continue; }
for(int i=1;i<=2*n;i++) {
if(vis[i]) continue;
vis[i] = 1;
if(DFS(i)) (ans *= 2) %= p;
else ans = 0;
}
cout<<ans<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 3788kb
input:
3 3 5 01100 10001 00010 2 1 1 1 2 3 001 001
output:
0 0 0
result:
wrong answer 1st numbers differ - expected: '4', found: '0'