QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#375319 | #2833. Hamilton | by_chance | WA | 1ms | 3892kb | C++14 | 1.4kb | 2024-04-03 08:59:50 | 2024-04-03 08:59:51 |
Judging History
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){
//for(int j=st;j!=n+1;j=nxt[j])printf("%d ",j);
//printf("\n%d %c %c\n",now,c1,c2);
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=0;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: 100
Accepted
time: 1ms
memory: 3892kb
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: 0
Accepted
time: 1ms
memory: 3784kb
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: -100
Wrong Answer
time: 0ms
memory: 3800kb
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 2 3 4 1 2 3 4 1 2 3 4 2 4 3 1 1 2 4 3 1 2 3 4 2 4 3 1 1 4 2 3 1 2 3 4
result:
wrong answer case #6: found 2 indices