QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#670333#7900. Gifts from Knowledgenahida_qaqWA 8ms5892kbC++232.0kb2024-10-23 21:20:552024-10-23 21:20:55

Judging History

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

  • [2024-10-23 21:20:55]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:5892kb
  • [2024-10-23 21:20:55]
  • 提交

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[N];
int dfs(int u)
{
    for(auto v:g[u])
    {
        if(st[v]==st[u])return 0;
        if(st[v])continue;
        st[v]=3^st[u];
        if(!dfs(v))return 0;
    }
    return 1;
}
void solve()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=2*n;i++)g[i].clear(),st[i]=0;
    vector<int>p[n+5];
    for(int i=1;i<=n;i++)
    {
        string s;
        cin>>s;
        s=' '+s;
        for(int j=1;j<=m;j++)
            if(s[j]=='1')p[j].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(p[x].size()+p[y].size()>2)
        {
            cout<<0<<'\n';
            return ;
        }
        if(p[x].size()+p[y].size()==2&&p[x].size()==1)
        {
            int u=p[y][0],v=p[x][0];
            if(u==v)continue;
            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()==2)
        {
            int u=p[x][0],v=p[x][1];
            g[u].pb(v);
            g[v].pb(u);
            g[u+n].pb(v+n);
            g[v+n].pb(u+n);
        }
        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);
        }
    }
    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;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 5668kb

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

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

result:

wrong answer 8th numbers differ - expected: '16', found: '0'