QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#382856#2833. HamiltonwaretleWA 0ms3932kbC++141.2kb2024-04-08 19:49:432024-04-08 19:49:43

Judging History

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

  • [2024-04-08 19:49:43]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3932kb
  • [2024-04-08 19:49:43]
  • 提交

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("");
    }
}

Details

Tip: Click on the bar to expand more detailed information

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