QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#375352 | #2833. Hamilton | hai | WA | 1ms | 5972kb | C++14 | 2.0kb | 2024-04-03 09:39:46 | 2024-04-03 09:39:47 |
Judging History
answer
# include <bits/stdc++.h>
# define N 2005
using namespace std;
int n;
char s[N][N];
bool col[N][N];
int to1[N],to2[N];
void add(int x,int y)
{
if(!to1[x])
to1[x]=y;
else
to2[x]=y;
if(!to1[y])
to1[y]=x;
else
to2[y]=x;
}
void del(int x,int y)
{
if(to1[x]==y)
to1[x]=0;
else
to2[x]=0;
if(to1[y]==x)
to1[y]=0;
else
to2[y]=0;
}
bool mark[N];
void solve()
{
for(int i=1;i<=n;i++)
scanf("%s",s[i]+1);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
col[i][j]=1;
add(1,2);
add(2,3);
add(3,1);
for(int i=4;i<=n;i++)
{
int id=-1;
for(int j=1;j<i;j++)
if(col[j][to1[j]]!=col[j][to2[j]])
{
id=j;
break;
}
if(id==-1)
{
int x=1,y=to1[1];
del(x,y);
add(x,i);
add(y,i);
}
else
{
if(col[id][to1[id]]==1)
swap(to1[id],to2[id]);
if(col[id][i]==0)
{
int x=id,y=to2[id];
del(x,y);
add(x,i);
add(y,i);
}
else
{
int x=id,y=to1[id];
del(x,y);
add(x,i);
add(y,i);
}
}
}
int id=-1;
for(int j=1;j<=n;j++)
if(col[j][to1[j]]!=col[j][to2[j]])
{
id=j;
break;
}
if(id==-1)
id=1;
int now=id;
while(1)
{
mark[now]=1;
cout<<now<<' ';
if(!mark[to1[now]])
now=to1[now];
else if(!mark[to2[now]])
now=to2[now];
else
break;
}
cout<<'\n';
for(int i=1;i<=n;i++)
to1[i]=to2[i]=mark[i]=0;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
while(cin>>n)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5972kb
input:
3 001 000 100 4 0000 0000 0000 0000
output:
1 2 3 1 2 3 1 1 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6...
result:
wrong answer case #2: not a permutation