QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#375317 | #2833. Hamilton | by_chance | WA | 1ms | 3900kb | C++14 | 1.1kb | 2024-04-03 08:53:21 | 2024-04-03 08:53:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2005;
int n,lst[N],nxt[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);
}
for(int i=st;i!=n+1;i=nxt[i])printf("%d ",i);
printf("\n");
}
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: 3900kb
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: 3800kb
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 2 3 1 2 3
result:
wrong answer case #3: found 2 indices