QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#21862#2833. HamiltonJackyqwq#WA 3ms5760kbC++141.5kb2022-03-08 17:01:352022-05-08 04:10:37

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 04:10:37]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:5760kb
  • [2022-03-08 17:01:35]
  • 提交

answer

#include <bits/stdc++.h>
//#define int long long
#define ll long long
#define db double
#define fi first
#define se second
#define pii pair<int,int>
#define vi vector<int>

using namespace std;

const int maxn=2e3; 
int n;
int nxt[maxn+5],pre[maxn+5]; 
char s[maxn+5][maxn+5]; 
int check(int x,int y,int z,int w) {
	int num=(s[x][y]!=s[y][z])+(s[y][z]!=s[z][w]);
	return num<=1; 
}
int main() {
	while (cin>>n) {
		for (int i=1;i<=n;i++) {
			scanf("%s",s[i]+1); 
			pre[i]=nxt[i]=0; 
		}
		int fir=1,lst=2; 
		nxt[1]=2,pre[2]=1;
		pre[1]=0;nxt[2]=0; 
		for (int i=3;i<=n;i++) {
			if (s[i][fir]=='0') {
				pre[fir]=i; nxt[i]=fir; fir=i; 
			}
			else if (s[i][lst]=='1') {
				nxt[lst]=i; pre[i]=lst; lst=i; 
			}
			else {
				int u=fir,x,y,z; 
				int flag=0; 
				while (u!=0) {
					int nx=nxt[u],nxx=nxt[nx];
					if (nxx){
						if (s[u][nx]!=s[nx][nxx]) {
							flag=1; 
							x=u,y=nx,z=nxx; 
							break ; 
						}
					}
					u=nxt[u];
				}
				if (flag==0) {
					if (s[fir][nxt[fir]]=='0') {
						nxt[lst]=i; pre[i]=lst; lst=i; 
					}
					else {
						pre[fir]=i; nxt[i]=fir; fir=i; 
					}
				}
				else {
					if (check(x,i,y,z)) {
						nxt[x]=i;
						pre[y]=i;
						nxt[i]=y;
						pre[i]=x; 
					}
					else {
						nxt[y]=i;
						pre[z]=i;
						nxt[i]=z;
						pre[i]=y; 
					}
				}
			}
		}
		int u=fir;
		for (int i=1;i<=n;i++) {
			printf("%d ",u); 
			u=nxt[u]; 
		}
		printf("\n"); 
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 3792kb

input:

3
001
000
100
4
0000
0000
0000
0000

output:

1 2 3 
4 3 1 2 

result:

ok 2 cases.

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 5760kb

input:

3
000
000
000
3
010
100
000
3
011
100
100
3
011
101
110

output:

3 1 2 
3 1 2 
3 1 2 
1 2 3 

result:

wrong answer case #2: found 2 indices