QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#666541 | #7900. Gifts from Knowledge | nahida_qaq | WA | 10ms | 5836kb | C++23 | 2.6kb | 2024-10-22 18:58:02 | 2024-10-22 18:58:11 |
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 fa[N];
int find(int x)
{
if(x==fa[x])return x;
return fa[x]=find(fa[x]);
}
void merge(int a,int b)
{
a=find(a),b=find(b);
if(a!=b)
{
fa[a]=b;
}
}
int st[N];
void dfs(int u,vector<int>g[])
{
st[u]=1;
for(auto v:g[u])
{
if(st[v])continue;
merge(u,v);
dfs(v,g);
}
}
int qmi(int a,int b,int mod)
{
int ans=1;
a=a%mod;
while(b)
{
if(b&1)ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
void solve()
{
int n,m;
cin>>n>>m;
vector<string>q(n+1);
for(int i=1;i<=2*n;i++)fa[i]=i,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 ;
}
}
vector<int>g[2*n+5];
for(int j=1;j<=m/2;j++)
{
int x=j,y=m-j+1;
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+n);
g[v].pb(u+n);
g[u+n].pb(v);
g[v+n].pb(u);
}
else if(p[x].size()+p[y].size()==2)
{
int u=p[y][0],v=p[x][0];
g[u].pb(v);
g[v].pb(u);
g[u+n].pb(v+n);
g[v+n].pb(u+n);
}
}
for(int i=1;i<=2*n;i++)
{
if(st[i])continue;
dfs(i,g);
}
int ans=0;
for(int i=1;i<=n;i++)
{
if(fa[i]==i)ans++;
if(fa[i]==fa[i+n])
{
cout<<0<<'\n';
return ;
}
}
for(int i=n+1;i<=2*n;i++)if(fa[i]==i)ans++;
cout<<qmi(2,ans/2,mod1)<<'\n';
}
signed main()
{
io;
int t=1;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5836kb
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: 10ms
memory: 5688kb
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'