QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#21862 | #2833. Hamilton | Jackyqwq# | WA | 3ms | 5760kb | C++14 | 1.5kb | 2022-03-08 17:01:35 | 2022-05-08 04:10:37 |
Judging History
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