QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#375318#2833. Hamiltonby_chanceWA 1ms3948kbC++141.3kb2024-04-03 08:57:382024-04-03 08:57:38

Judging History

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

  • [2024-04-03 08:57:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3948kb
  • [2024-04-03 08:57:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2005;
int n,lst[N],nxt[N],a[N];char s[N][N];
void solve(int st){
	for(int i=0;i<=n+1;i++)lst[i]=nxt[i]=0;
	lst[st]=0;nxt[0]=st;lst[n+1]=st;nxt[st]=n+1;
	char c1='1',c2='0';int now=st;
	for(int i=1;i<=n;i++)if(i!=st){
		if(nxt[now]==n+1){
			nxt[now]=i;nxt[i]=n+1;
			lst[n+1]=i;lst[i]=now;
			if(s[now][i]==c1)now=i;
		}
		else{
			if(s[now][i]==c2&&s[nxt[now]][i]==c1){
				int tmp=(s[lst[now]][i]==c2?lst[now]:i);
				nxt[lst[now]]=i;lst[i]=lst[now];
				nxt[i]=now;lst[now]=i;now=tmp;
			}
			else{
				int tmp;
				if(s[now][i]==c2)tmp=now;
				else if(s[nxt[now]][i]==c2)tmp=i;
				else tmp=nxt[now];
				lst[nxt[now]]=i;nxt[i]=nxt[now];
				lst[i]=now;nxt[now]=i;now=tmp;
			}
		}
		if(now==st)now=lst[n+1],swap(c1,c2);
	}
    int k=0;for(int i=st;i!=n+1;i=nxt[i])a[k++]=i;
	for(int i=1;i<=n;i++){
        int cnt=0;
        for(int j=0;j<n-1;j++){
            int u=a[i+j],v=a[(i+j+1)%n],w=a[(i+j+2)%n];
            if(s[u][v]!=s[v][w])++cnt;
        }
        if(cnt<=1){
            for(int j=0;j<n;j++)
                printf("%d ",a[(i+j)%n]);
            printf("\n");return;
        }
    }
}
int main(){
    while(scanf("%d",&n)!=EOF){
	    for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
	    solve(1);
    }
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3948kb

input:

3
001
000
100
4
0000
0000
0000
0000

output:

2 3 4 1 

result:

wrong answer Integer 4 violates the range [1, 3]