QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#80678 | #5523. Graph Problem With Small $n$ | zhouhuanyi | WA | 1779ms | 228416kb | C++14 | 1.9kb | 2023-02-24 17:29:54 | 2023-02-24 17:29:57 |
Judging History
answer
#include<iostream>
#include<cstdio>
#define N 24
#define M 2704156
#define K 12
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
int lowbit(int x)
{
return x&(-x);
}
int n,sz[1<<N],B[N+1],S[1<<N],tong[2][M+1],length[2],dp[2][M+1][K+1],num[M+1],st[N+1],leng,st2[N+1],leng2;
char c[N+1][N+1];
bool E[N+1][N+1];
int main()
{
bool op=0;
n=read();
for (int i=1;i<(1<<n);++i) sz[i]=sz[i-lowbit(i)]+1;
for (int i=1;i<=n;++i)
for (int j=1;j<=n;++j)
cin>>c[i][j];
for (int i=1;i<=n;++i)
for (int j=1;j<=n;++j)
if (c[i][j]=='1')
B[i]|=(1<<(j-1));
for (int i=0;i<(1<<n);++i)
for (int j=1;j<=n;++j)
if (i&(1<<(j-1)))
S[i]|=B[j];
for (int i=1;i<=n;++i) tong[0][++length[0]]=(1<<(i-1)),num[1<<(i-1)]=length[0],dp[0][num[1<<(i-1)]][1]=(1<<(i-1));
for (int i=2;i<=((n+1)>>1);++i)
{
op^=1,length[op]=0;
for (int j=0;j<(1<<n);++j)
if (sz[j]==i)
{
tong[op][++length[op]]=j,num[j]=length[op],leng=0;
for (int k=1;k<=sz[j];++k) dp[op][length[op]][k]=0;
for (int k=1;k<=n;++k)
if (j&(1<<(k-1)))
st[++leng]=k;
for (int k=1;k<=leng;++k)
for (int t=1;t<=leng;++t)
if (k!=t&&c[st[t]][st[k]]=='1')
dp[op][num[j]][k]|=dp[op^1][num[j^(1<<(st[k]-1))]][t-(t>k)];
}
}
for (int i=0;i<(1<<n);++i)
if (sz[i]==((n+1)>>1))
{
leng=leng2=0;
for (int j=1;j<=n;++j)
{
if (i&(1<<(j-1))) st[++leng]=j;
else st2[++leng2]=j;
}
for (int j=1;j<=leng;++j)
for (int k=1;k<=leng2;++k)
if (S[dp[op][num[i]][j]]&dp[op^(n&1)][num[((1<<n)-1)^i]][k])
E[st[j]][st2[k]]=1;
}
for (int i=1;i<=n;++i)
{
for (int j=1;j<=n;++j) printf("%d",E[i][j]);
puts("");
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 9660kb
input:
4 0110 1010 1101 0010
output:
0001 0001 0000 1100
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 7676kb
input:
6 010001 101000 010100 001010 000101 100010
output:
010001 101000 010100 001010 000101 100010
result:
ok 6 lines
Test #3:
score: 0
Accepted
time: 2ms
memory: 7816kb
input:
4 0111 1011 1101 1110
output:
0111 1011 1101 1110
result:
ok 4 lines
Test #4:
score: 0
Accepted
time: 1534ms
memory: 227548kb
input:
23 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 000000000...
output:
00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 000000000000...
result:
ok 23 lines
Test #5:
score: -100
Wrong Answer
time: 1779ms
memory: 228416kb
input:
23 00010100000000000101000 00000000010000000001000 00000000000001000000001 10000000000000000010000 00000000000000000000000 10000000000000000000000 00000001000000000000000 00000010000000000010000 00000000000001000000000 01000000000000000000000 00000000000000000000000 00000000000000000000000 000000000...
output:
01111111111111111111111 10110111000101001100011 11011111111111111111111 11101111111111111111111 00000000000000000000000 01111011111110111111111 11110100010001001111011 11111100110011001100111 01111111011110111111111 10111111101111111110111 00000000000000000000000 00000000000000000000000 000000000000...
result:
wrong answer 1st lines differ - expected: '00000000000000000000000', found: '01111111111111111111111'