QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#80679#5523. Graph Problem With Small $n$zhouhuanyiTL 1791ms250588kbC++141.9kb2023-02-24 17:43:592023-02-24 17:43:59

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-24 17:43:59]
  • 评测
  • 测评结果:TL
  • 用时:1791ms
  • 内存:250588kb
  • [2023-02-24 17:43:59]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cassert>
#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[1<<N],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][num[j]][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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 11720kb

input:

4
0110
1010
1101
0010

output:

0001
0001
0000
1100

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 2ms
memory: 11704kb

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: 1ms
memory: 11900kb

input:

4
0111
1011
1101
1110

output:

0111
1011
1101
1110

result:

ok 4 lines

Test #4:

score: 0
Accepted
time: 1510ms
memory: 249912kb

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: 0
Accepted
time: 1791ms
memory: 250588kb

input:

23
00010100000000000101000
00000000010000000001000
00000000000001000000001
10000000000000000010000
00000000000000000000000
10000000000000000000000
00000001000000000000000
00000010000000000010000
00000000000001000000000
01000000000000000000000
00000000000000000000000
00000000000000000000000
000000000...

output:

00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
000000000000...

result:

ok 23 lines

Test #6:

score: -100
Time Limit Exceeded

input:

23
00001000000000000000000
00001000010001000000000
00000000000101000010000
00001000000100000000000
11010000010011000100000
00000000000100000000000
00000000000000000000001
00000000000000000101000
00000000000000000000000
01001000000000101010010
00000000000000000000101
00110100000010001000000
000010000...

output:


result: