QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#382856 | #2833. Hamilton | waretle | WA | 0ms | 3932kb | C++14 | 1.2kb | 2024-04-08 19:49:43 | 2024-04-08 19:49:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int n,p[2005],cur;
char mp[2005][2005];
int c(int i){return i==cur?mp[p[cur]][p[1]]:mp[p[i]][p[i+1]];}
int nxt(int i){return i==cur?1:i+1;}
void ins(int x,int y)
{
for(int i=cur+1;i>x;--i)p[i]=p[i-1];
p[x]=y;
}
int main()
{
while(~scanf("%d",&n))
{
for(int i=1;i<=n;++i)scanf("%s",mp[i]+1);
for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)mp[i][j]-='0';
p[1]=1,p[2]=2;
for(int i=3;i<=n;++i)
{
cur=i-1;
int pos=0;
for(int j=1;j<i;++j)
if(c(j)!=c(nxt(j)))
assert(!pos),pos=j;
if(!pos)p[i]=i;
else
{
if(mp[p[pos]][i]==mp[p[nxt(pos)]][i])
ins(pos+1,i);
else if(mp[p[nxt(pos)]][i]==mp[p[nxt(nxt(pos))]][i])
ins(pos+2,i);
else if(mp[p[nxt(pos)]][i]==c(pos))
ins(pos+2,i);
else ins(pos+1,i);
}
}
for(int i=1;i<=n;++i)printf("%d ",p[i]);
puts("");
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3932kb
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: 0ms
memory: 3912kb
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