QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#375582 | #2833. Hamilton | World_Creater | WA | 1ms | 3656kb | C++14 | 1011b | 2024-04-03 13:41:39 | 2024-04-03 13:41:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,nxt[2005],lst[2005];
char mp[2005][2005];
int main()
{
while(cin>>n)
{
for(int i=1;i<=n;i++)
{
cin>>mp[i]+1;
for(int j=1;j<=n;j++)
{
mp[i][j]-='0';
}
}
nxt[n+1]=1;
lst[1]=n+1;
int pos=1,pt=-1;
for(int i=2;i<=n;i++)
{
if(!nxt[pos])
{
nxt[pos]=i;
lst[pos]=i;
if(pt==-1||pt==mp[pos][i])
{
pt=mp[pos][i];
pos=i;
}
}
else
{
if(mp[pos][i]==pt)
{
nxt[i]=nxt[pos];
lst[nxt[pos]]=i;
lst[i]=pos;
nxt[pos]=i;
}
else
{
lst[i]=lst[pos];
nxt[lst[pos]]=i;
nxt[i]=pos;
lst[pos]=i;
while(lst[pos]&&(lst[pos]==n+1||mp[pos][lst[pos]]==(pt^1))) pos=lst[pos];
if(pos==n+1) pt^=1;
}
while(nxt[pos]&&mp[pos][nxt[pos]]==pt) pos=nxt[pos];
}
}
for(int i=nxt[n+1];i;i=nxt[i])
{
cout<<i<<" ";
}
cout<<"\n";
for(int i=1;i<=n+1;i++) nxt[i]=lst[i]=0;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3656kb
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: 1ms
memory: 3552kb
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