QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#505185#2833. Hamiltonliyixin0514WA 0ms3824kbC++141.8kb2024-08-04 21:31:272024-08-04 21:31:27

Judging History

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

  • [2024-08-04 21:31:27]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3824kb
  • [2024-08-04 21:31:27]
  • 提交

answer

#include<bits/stdc++.h>
// #define LOCAL
#define sf scanf
#define pf printf
#define rep(x,y,z) for(int x=y;x<=z;x++)
using namespace std;
typedef long long ll;
const int N=2e3+5;
int n;
int c[N][N];
int a[N],b[N];
int cnt[2];
int read(){
    char ch=getchar();
    while(ch!='0'&&ch!='1') ch=getchar();
    return ch-'0';
}
int main(){
    #ifdef LOCAL
    freopen("in.txt","r",stdin);
    freopen("my.out","w",stdout);
    #endif
    while(cin>>n){
        cnt[0]=cnt[1]=0;
        // pf("%d\n",n);
        rep(i,1,n) rep(j,1,n) c[i][j]=read();
        // pf("\n");
        a[1]=2,a[2]=3,a[3]=1;
        b[1]=3,b[2]=1,b[3]=2;
        cnt[c[1][2]]++,cnt[c[2][3]]++,cnt[c[1][3]]++;
        rep(i,4,n){
            rep(j,1,i-1){
                int coll=c[j][b[j]],colr=c[a[j]][a[a[j]]],coln=c[j][a[j]];
                int myl=c[i][j],myr=c[i][a[j]];
                if(coll==myl&&colr==myr) {
                    cnt[myl]++;cnt[myr]++;
                    cnt[coln]--;
                    a[i]=a[j],b[i]=j;
                    a[j]=i,b[a[i]]=i;
                    break;
                }else {
                    cnt[coln]--;
                    if(cnt[0]*cnt[1]==0) {
                        cnt[myl]++;cnt[myr]++;
                        cnt[coln]--;
                        a[i]=a[j],b[i]=j;
                        a[j]=i,b[a[i]]=i;
                        cnt[coln]++;
                        break;
                    }
                    cnt[coln]++;
                }
            }
        }
        int rt=1;
        if(cnt[0]*cnt[1]==0) rt=1;
        else{
            rep(i,1,n){
                if(c[rt][a[rt]]!=c[rt][b[rt]]) break;
                rt=a[rt];
            }
        }
        rep(i,1,n) {
            pf("%d ",rt);
            rt=a[rt];
        }
        pf("\n");
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3752kb

input:

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

output:

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

result:

ok 4 cases.

Test #3:

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

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 
4 2 3 1 
1 2 3 4 
4 2 3 1 
1 4 2 3 
1 4 2 3 
1 4 2 3 
4 2 3 1 
3 4 1 2 
1 4 2 3 
1 2 3 4 

result:

ok 11 cases.

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3824kb

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 5 4 2 3 
1 4 2 3 1 
5 4 2 3 1 
1 5 4 2 3 
5 4 2 3 1 
4 3 1 5 2 
1 4 2 3 1 
1 5 4 2 3 
1 5 4 2 3 
1 5 4 2 3 
4 3 1 5 2 
4 3 1 5 2 
1 5 2 4 3 
5 4 2 3 1 
4 3 5 1 2 
4 5 2 3 1 
5 4 2 3 1 
5 2 3 4 1 
1 4 5 2 3 
1 5 4 2 3 
2 4 3 1 2 
4 5 2 3 1 
4 3 5 1 2 
5 4 2 3 1 
4 2 3 1 4 
5 4 2 3 1 
1 5...

result:

wrong answer case #3: not a permutation