QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#672093 | #7900. Gifts from Knowledge | wsy_jim# | WA | 36ms | 11784kb | C++14 | 4.8kb | 2024-10-24 15:35:46 | 2024-10-24 15:35:46 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdlib>
#include<ctime>
#include<bitset>
#include<vector>
#include<climits>
#include<iomanip>
using namespace std;
#define N 1500010
#define ll long long
template<typename T>
inline void read(T &x){
x=0;bool flg=0;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') flg=1;
for(;isdigit(c);c=getchar()) x=x*10+(c^48);
if(flg) x=-x;
}
const ll Mod=1e9+7;
int n;
int t;
int r,c,idea=1;
int e[N],ne[N],idx,h[N],w[N],vis[N];
void add(int a,int b,int c){
e[idx]=b,ne[idx]=h[a],w[idx]=c,h[a]=idx++;
}
void dfs(int x,int fa){
//cout<<idea<<endl;
for(int i=h[x];~i;i=ne[i]){
int j=e[i];
if(j==fa) continue;
if(vis[j]){
if(w[i]==0&&vis[j]!=vis[x]) idea=0;
if(w[i]==1&&vis[j]==vis[x]) idea=0;
}
if(j==fa||vis[j]) continue;
if(w[i]) vis[j]=vis[x];
else vis[j]=-vis[x];
dfs(j,x);
}
}
int main(){
read(t);
while(t--){
read(r),read(c);idx=0;
ll res=1;
vector<vector<int>> mapp(r+1,vector<int>(c+1,0));
for(int i=1;i<=r;i++){
string str;
cin>>str;h[i]=-1;vis[i]=0;
for(int j=1;j<=c;j++){
mapp[i][j]=str[j-1]=='0'?0:1;
}
}
idea=1;
if(c%2){
int sum=0;
for(int i=1;i<=r;i++){
if(mapp[i][c/2+1]) sum++;
}
if(sum>1) idea=0;
}
for(int i=1;i<=c/2;i++){
vector<int> le,re;
for(int j=1;j<=r;j++){
if(mapp[j][i]) le.push_back(j);
if(mapp[j][c+1-i]) re.push_back(j);
}
if(le.size()+re.size()>2) idea=0;
if(le.size()==2){
add(le[0],le[1],1);
add(le[1],le[0],1);
}else if(re.size()==2){
add(re[0],re[1],1);
add(re[1],re[0],1);
}else if(le.size()==1&&re.size()==1&&le[0]!=re[0]){
add(le[0],re[0],0);
add(re[0],le[0],0);
}
// if(le.size()==2){
// if(vis[le[0]]==0&&vis[le[1]]==0){
// if(!res) res=2;
// else (res*=2)%=Mod;
// vis[le[0]]=1;
// vis[le[1]]=-1;
// }else if(vis[le[0]]==0){
// vis[le[1]]=-vis[le[0]];
// }else if(vis[le[1]]==0){
// vis[le[0]]=-vis[le[1]];
// }else if(vis[le[0]]+vis[le[1]]) idea=0;
// }
// if(re.size()==2){
// if(vis[re[0]]==0&&vis[re[1]]==0){
// if(!res) res=2;
// else (res*=2)%=Mod;
// vis[re[0]]=1;
// vis[re[1]]=-1;
// }else if(vis[re[0]]==0){
// vis[re[1]]=-vis[re[0]];
// }else if(vis[re[1]]==0){
// vis[re[0]]=-vis[re[1]];
// }else if(vis[re[0]]+vis[re[1]]) idea=0;
// }
// if(re.size()==1&&le.size()==1){
// if(vis[re[0]]==0&&vis[le[0]]==0){
// if(!res) res=2;
// else (res*=2)%=Mod;
// vis[re[0]]=1;
// vis[le[0]]=-1;
// }else if(vis[re[0]]==0){
// vis[le[0]]=-vis[re[0]];
// }else if(vis[le[0]]==0){
// vis[re[0]]=-vis[le[0]];
// }else if(vis[re[0]]!=vis[le[0]]) idea=0;
// }
// if(re.size()==1&&le.size()==1&&re[0]==le[0]){
// if(vis[re[0]]==0){
// if(!res) res=2;
// else (res*=2)%=Mod;
// vis[re[0]]=1;
// }else{
// }
// }
// if(re.size()==1&&le.size()==1){
// if(vis[re[0]]==0&&vis[le[0]]==0){
// if(!res) res=2;
// else (res*=2)%=Mod;
// vis[re[0]]=1;
// vis[le[0]]=-1;
// }else if(vis[re[0]]==0){
// vis[le[0]]=-vis[re[0]];
// }else if(vis[le[0]]==0){
// vis[re[0]]=-vis[le[0]];
// }else if(vis[re[0]]!=vis[le[0]]) idea=0;
// }
}
for(int i=1;i<=r;i++){
if(!vis[i]) vis[i]=1,dfs(i,0),(res*=2ll)%=Mod;
}
if(!idea) cout<<0<<endl;
else cout<<res<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 11772kb
input:
3 3 5 01100 10001 00010 2 1 1 1 2 3 001 001
output:
4 0 2
result:
ok 3 number(s): "4 0 2"
Test #2:
score: 0
Accepted
time: 36ms
memory: 7712kb
input:
15613 10 10 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 15 8 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 1 5 00000 5 9 000000000 000000000 0000...
output:
1024 32768 2 32 32768 128 32 16 16 2 16384 16384 128 128 32768 8192 128 64 16384 2 4 2 4096 16 4096 1024 32768 32768 16384 8 128 2 16 4096 8192 32768 8192 8192 16 16384 16384 256 128 8 256 8 4096 512 2 4 32 32 2 64 512 1024 32768 32768 2 64 16384 16 8192 16 256 16 64 8192 8192 64 1024 2 32768 2 4 51...
result:
ok 15613 numbers
Test #3:
score: -100
Wrong Answer
time: 27ms
memory: 11784kb
input:
15759 9 6 000000 000000 000000 000000 000000 000000 000000 000000 000000 5 15 010000000000000 000000000000000 000000000000000 000100000000000 000100000000000 14 12 000000000000 000000000000 000000000000 000000000000 000000000000 000000000000 000000000000 000000000000 000000000000 000000000000 000000...
output:
512 16 16384 512 1024 4096 32768 4 2 512 512 512 512 8 2 256 16 4096 512 64 16 4096 512 32 32768 8192 32 2048 128 16 4096 64 32768 256 32 16384 8 512 32 2048 8 16 1024 2048 128 64 32 8 512 8 8192 256 8192 32768 2 8 512 512 256 32 2 2048 8192 8 64 8 2 16384 32768 32768 1024 4096 16384 16384 128 256 4...
result:
wrong answer 1014th numbers differ - expected: '2', found: '0'