QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#666659 | #7900. Gifts from Knowledge | nahida_qaq | WA | 8ms | 5668kb | C++23 | 2.2kb | 2024-10-22 19:31:22 | 2024-10-22 19:31:28 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define io ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pb push_back
using namespace std;
const int N=2e6+5,mod1=1e9+7,mod2=998244353;
typedef pair<int,int> pi;
int st[N];
vector<int>g[2000005];
int dfs(int u)
{
for(int i=0;i<g[u].size();i++)
{
int v = g[u][i];
if(st[v]==st[u]) return 0;
if(st[v]) continue;
st[v] = (st[u]==1)?2:1;
if(!dfs(v)) return 0;
}
return 1;
}
void solve()
{
int n,m;
cin>>n>>m;
vector<string>q(n+1);
for(int i=1;i<=2*n;i++)g[i].clear(),st[i]=0;
for(int i=1;i<=n;i++)cin>>q[i];
vector<int>b(m+5);
vector<int>p[n+5];
for(int i=1;i<=n;i++)
for(int j=0;j<m;j++)
{
if(q[i][j]=='1')
{
b[j+1]++;
if(b[j+1]>2)
{
cout<<0<<'\n';
return ;
}
p[j+1].pb(i);
}
}
if(m&1)
{
if(p[m/2+1].size()>1)
{
cout<<0<<'\n';
return ;
}
}
for(int i=1;i<=n;i++)
{
g[i].pb(i+n);
g[i+n].pb(i);
}
for(int j=1;j<=m/2;j++)
{
int x=j,y=m-j+1;
if(x==y)continue;
if(p[x].size()==2)
{
int u=p[x][0],v=p[x][1];
g[u].pb(v+n);
g[v].pb(u+n);
g[u+n].pb(v);
g[v+n].pb(u);
}
else if(p[y].size()==2)
{
int u=p[y][0],v=p[y][1];
g[u].pb(v);
g[v].pb(u);
g[u+n].pb(v+n);
g[v+n].pb(u+n);
}
else if(p[x].size()+p[y].size()==2)
{
int u=p[y][0],v=p[x][0];
g[u].pb(v+n);
g[v].pb(u+n);
g[u+n].pb(v);
g[v+n].pb(u);
}
}
int ans=1;
for(int i=1;i<=2*n;i++)
{
if(st[i])continue;
st[i]=1;
if(!dfs(i))ans=0;
else ans=ans*2%mod1;
}
cout<<ans<<'\n';
}
signed main()
{
io;
int t=1;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5568kb
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: -100
Wrong Answer
time: 8ms
memory: 5668kb
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 0 2 4096 16 4096 1024 32768 32768 16384 8 128 0 16 4096 8192 32768 8192 8192 16 16384 16384 256 128 0 256 8 4096 512 2 4 32 32 0 64 512 1024 32768 32768 2 64 16384 16 8192 16 256 16 64 8192 8192 64 1024 2 32768 2 4 51...
result:
wrong answer 21st numbers differ - expected: '4', found: '0'