QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#666609#7900. Gifts from Knowledgenahida_qaqRE 1ms5584kbC++232.2kb2024-10-22 19:19:562024-10-22 19:20:03

Judging History

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

  • [2024-10-22 19:20:03]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5584kb
  • [2024-10-22 19:19:56]
  • 提交

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 st[N];
int dfs(int u,vector<int>g[])
{
    for(auto v:g[u])
    {
        if(st[v]==st[u])return 0;
        if(st[v])continue;
        st[v]=3-st[u];
        return dfs(v,g);
    }
    return 1;
}
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 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+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);
        }
    }
    int ans=1;
    for(int i=1;i<=2*n;i++)
    {
        if(st[i])continue;
        st[i]=1;
        dfs(i,g);
        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: 1ms
memory: 5584kb

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
Runtime Error

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:


result: