QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#303640#2833. Hamiltonminaduki_mapleRE 0ms3720kbC++201.8kb2024-01-12 20:36:542024-01-12 20:36:55

Judging History

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

  • [2024-01-12 20:36:55]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3720kb
  • [2024-01-12 20:36:54]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,j,k) for(int i=j;i<=k;++i)
using namespace std;
int read(){
    int x=0,fh=1; char ch=getchar();
    for (;!isdigit(ch);ch=getchar()) if (ch=='-') fh=-1;
    for (;isdigit(ch);ch=getchar()) x=x*10+(ch^48);
    return x*fh;
}
//20:00-
char c[2005]; bool f[2005][2005];
int a[2005],n;
void ins(int len,int x,int val){
    for(int i=len;i>=x;--i) a[i+1]=a[i];
    a[x]=val;
}
int get(int x){if (x<=0) x+=n; if (x>n) x-=n; return x;}
int main(){
    while(scanf("%d",&n)!=EOF){
        For(i,1,n){
            scanf("%s",c+1);
            For(j,1,n) f[i][j]=c[j]-48;
        }
        For(i,1,3) a[i]=i;
        For(now,4,n){
            bool flag=0;
            For(i,1,now-1){
                int l=a[i],r=a[get(i+1)],xl=a[get(i-1)],xr=a[get(i+2)];
                int cnt=0;
                if (f[xl][l]!=f[l][r]) ++cnt;
                if (f[l][r]!=f[r][xr]) ++cnt;
                if (cnt>=0){
                    int ct=0;
                    if (f[xl][l]!=f[l][now]) ++ct;
                    if (f[l][now]!=f[now][r]) ++ct;
                    if (f[now][r]!=f[r][xr]) ++ct;
                    if (ct<=cnt) {ins(now-1,i+1,now),flag=1; break;}
                }
            }
            if (!flag) ins(now-1,1,now);
        }
        //pr
        For(i,1,n){
            int ct=0;
            For(j,1,n-1) if (f[ a[j] ][ a[j+1] ]!=f[ a[j+1] ][ a[get(j+2)] ]) ++ct;
            if (ct<=1) {
                For(j,1,n) printf("%d ",a[j]); printf("\n"); break;
            }
            if (i==n) exit(54545144);
            ins(n,1,a[n]);
        }
    }
    return 0;
}
/*
ample Input
3
001
000
100
4
0000
0000
0000
0000
3
011
100
100
3
010
100
000
3
010
101
010
3
001
000
100
3
001
001
110
3
000
001
010
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
001
000
100
4
0000
0000
0000
0000

output:

1 2 3 
1 4 2 3 

result:

ok 2 cases.

Test #2:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

3
000
000
000
3
010
100
000
3
011
100
100
3
011
101
110

output:

1 2 3 
1 2 3 
3 1 2 
1 2 3 

result:

ok 4 cases.

Test #3:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

4
0000
0000
0000
0000
4
0000
0001
0000
0100
4
0100
1010
0100
0000
4
0111
1000
1000
1000
4
0010
0011
1101
0110
4
0111
1011
1100
1100
4
0111
1011
1101
1110
4
0000
0011
0101
0110
4
0101
1010
0100
1000
4
0011
0011
1100
1100
4
0010
0001
1000
0100

output:

1 4 2 3 
1 2 3 4 
3 1 4 2 
3 1 4 2 
1 4 2 3 
1 4 2 3 
1 4 2 3 
3 1 4 2 
4 1 2 3 
1 4 2 3 
1 2 3 4 

result:

ok 11 cases.

Test #4:

score: -100
Runtime Error

input:

5
00000
00000
00000
00000
00000
5
00001
00000
00000
00000
10000
5
00010
00010
00000
11000
00000
5
00000
00001
00001
00001
01110
5
00001
00001
00001
00001
11110
5
00101
00100
11011
00100
10100
5
01111
10011
10000
11000
11000
5
00011
00011
00011
11101
11110
5
01101
10111
11001
01001
11110
5
00111
0011...

output:

1 5 4 2 3 
1 4 5 2 3 
4 5 1 2 3 
5 1 4 2 3 
3 5 1 4 2 
1 4 5 2 3 
3 1 4 2 5 
1 5 4 2 3 
4 5 1 2 3 
1 5 4 2 3 
1 5 4 2 3 
3 1 5 4 2 
3 1 5 2 4 
3 1 4 5 2 
3 1 5 4 2 
3 1 5 4 2 
4 1 2 3 5 
3 1 5 2 4 
3 1 4 5 2 
1 2 5 4 3 
3 1 2 5 4 
5 1 4 2 3 
1 5 4 2 3 
1 5 4 2 3 
4 2 3 1 5 
1 2 4 5 3 
4 1 2 3 5 
1 5...

result: