QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#375582#2833. HamiltonWorld_CreaterWA 1ms3656kbC++141011b2024-04-03 13:41:392024-04-03 13:41:40

Judging History

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

  • [2024-04-03 13:41:40]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3656kb
  • [2024-04-03 13:41:39]
  • 提交

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