QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#664708#7900. Gifts from Knowledgenahida_qaqWA 10ms5644kbC++232.5kb2024-10-21 21:51:512024-10-21 21:51:52

Judging History

你现在查看的是最新测评结果

  • [2024-10-21 21:51:52]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:5644kb
  • [2024-10-21 21:51:51]
  • 提交

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)
    {
        cout<<0<<'\n';
        return ;
    }
    vector<int>g[2*n+5];
    for(int j=1;j<=m;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: 5644kb

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: 5548kb

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
0
8192
16
16384
16384
256
128
8
256
8
4096
512
2
4
32
0
2
64
512
1024
32768
32768
2
64
16384
16
8192
16
256
16
64
8192
8192
64
1024
2
32768
2
4
512
40...

result:

wrong answer 37th numbers differ - expected: '8192', found: '0'