QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#376011#2833. HamiltonzhouqixuanWA 0ms3932kbC++141.4kb2024-04-03 19:42:342024-04-03 19:42:35

Judging History

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

  • [2024-04-03 19:42:35]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3932kb
  • [2024-04-03 19:42:34]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=2010;
int n;
char c[N][N];
int ne[N];
void insert(int x,int k){
    int t=ne[x];
    ne[x]=k,ne[k]=t;
    return;
}
void calc(){
    for(int i=1;i<=n;i++) ne[i]=0;
    ne[1]=1;
    for(int l=2;l<=n;l++){
        int t1=0,t0=0;
        for(int i=1;;i=ne[i]){
            if(c[i][ne[i]]=='0') t0=1;
            else t1=1;
            // cout<<"!"<<i<<" "<<ne[i]<<" "<<c[i][ne[i]]<<endl;
            if(ne[i]==1) break;
        }
        // cout<<t0<<" "<<t1<<endl;
        if(t1+t0==1) insert(l-1,l);
        else{
            // cout<<l<<endl;
            for(int i=1;;i=ne[i]){
                int j=ne[i];int k=ne[j];
                if(c[i][j]=='1' && c[j][k]=='0'){
                    if(c[j][l]=='0') insert(i,l);
                    else insert(j,l);
                    break;
                }
            }
        }
    }
    int cnt=0;
    for(int i=1;;i=ne[i]){
        if(c[i][ne[i]]!=c[ne[i]][ne[ne[i]]]) cnt++;
        if(ne[ne[i]]==1) break;
    }
    if(cnt>1){
        puts("-1");
        return;
    }
    for(int i=1;;i=ne[i]){
        printf("%d ",i);
        if(ne[i]==1) break;
    }
    puts("");
    return;
}
int main(){
    while(scanf("%d",&n)!=-1){
        for(int i=1;i<=n;i++) scanf("%s",c[i]+1);
        calc();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
001
000
100
4
0000
0000
0000
0000

output:

1 2 3 
1 2 3 4 

result:

ok 2 cases.

Test #2:

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

input:

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

output:

1 2 3 
1 2 3 
-1
1 2 3 

result:

wrong answer case #3: user does not find a solution