QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#512353#5523. Graph Problem With Small $n$Monkey_LeeWA 23ms136908kbC++202.3kb2024-08-10 14:15:472024-08-10 14:15:51

Judging History

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

  • [2024-08-10 14:15:51]
  • 评测
  • 测评结果:WA
  • 用时:23ms
  • 内存:136908kb
  • [2024-08-10 14:15:47]
  • 提交

answer

#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int maxs=(1<<24);
const int maxn=24;
int n,f[maxs],g[maxs],tmp[maxs];
int ans[maxn][maxn];
char mp[maxn][maxn];
int main()
{
    scanf("%d",&n);
    // n=24;
    // int t=clock();
    // srand(time(0));
    // for(int i=0;i<n;i++)
        // for(int j=0;j<i;j++)
            // mp[j][i]=mp[i][j]='1';//+(rand()%2==0);
    int fuck = 0;
    for(int i=0;i<n;i++)
    {
        scanf("%s",mp[i]);
        for(int j=0;j<n;j++)
            mp[i][j]=(i==j?'0':'1');
        for(int j=0;j<n;j++)
            if(mp[i][j]=='1')
                g[1<<i]|=(1<<j) , fuck += (1<<j);
    }
    if( n == 24 ) {
        printf("%d\n",fuck);
        for(int i = 12;i < n;++i) printf("%s\n",mp[i]);
    }
    int S=(1<<n)-1,SS=S;
    int i=n-1;
    SS^=(1<<i);
    memset(f,0,sizeof(f));
    f[1<<i]=1<<i;
    for(int j=1;j<S;j++)
        if((j&(1<<i))&&(j==S-1||(j&SS)!=SS))
        {
            int now=S^j;
            while(now)
            {
                int p=now&(-now);
                (g[p]&f[j])&&(f[j|p]|=p),now^=p;
            }
        }
    
    for(int j=0;j+1<n;j++)
        if(f[S]&(1<<j))
            ans[n-1][j]=ans[j][n-1]=1;
    memcpy(tmp,f,sizeof(tmp));
    int tmp2=S;S=SS;
    for(int i=0;i+1<n-1;i++)
    {
        SS^=(1<<i);
        memset(f,0,sizeof(f));
        f[1<<i]=1<<i;
        for(int j=1;j<S;j++)
            if((j&(1<<i))&&(j==S-1||(j&SS)!=SS))
            {
                int now=S^j;
                while(now)
                {
                    int p=now&(-now);
                    (g[p]&f[j])&&(f[j|p]|=p),now^=p;
                }
            }
        int state=0;
        for (int j=1;j<S;j++)
            if (j&(1<<i))
            {
                if ((f[j]&g[1<<(n-1)])==0)continue;
                state|=tmp[tmp2^j];
            }
        for(int j=i+1;j<n;j++)
            if(state&(1<<j))
                ans[i][j]=1;
    }
    for(int i=0;i<n;i++)
        for(int j=0;j<i;j++)
            ans[i][j]=ans[j][i];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
            printf("%d",ans[i][j]);
        puts("");
    }
    // printf("%.3lf\n",1.0*(clock()-t)/CLOCKS_PER_SEC);
//qwq
    return 0;
}   

詳細信息

Test #1:

score: 0
Wrong Answer
time: 23ms
memory: 136908kb

input:

4
0110
1010
1101
0010

output:

0111
1011
1101
1110

result:

wrong answer 1st lines differ - expected: '0001', found: '0111'