QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#21950#2833. HamiltonWhybullYMe#WA 3ms3620kbC++141.5kb2022-03-08 18:53:502022-05-08 04:19:15

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:19:15]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3620kb
  • [2022-03-08 18:53:50]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
int n,a[2001][2001];
vector<pair<int,int> > v;
int main()
{
    while(cin>>n)
    {
        v.clear();
        for(int i=1;i<=n;++i)
            for(int j=1;j<=n;++j)
            {
                a[i][j]=getchar()^48;
                while(a[i][j]<0||a[i][j]>1)
                    a[i][j]=getchar()^48;
            }
        v.push_back({1,a[1][2]});
        v.push_back({2,a[2][3]});
        v.push_back({3,a[3][1]});
        for(int i=4;i<=n;++i)
        {
            int pos=0;
            for(int j=0;j<(int)v.size();++j)
                if(v[j].second^v[(j+1)%(i-1)].second)
                {
                    pos=j;
                    break;
                }
            int val=a[i][v[(pos+1)%(i-1)].first];
            if(val==v[pos].second)
            {
                v[(pos+1)%(i-1)].second=v[pos].second;
                v.insert(v.begin()+(pos+2)%(i-1),{i,a[i][v[(pos+2)%(i-1)].first]});
            }
            else
            {
                v.insert(v.begin()+(pos+1)%(i-1),{i,val});
                v[pos].second=a[i][v[pos].first];
            }
        }
        int pos=0;
        for(int i=0;i<n;++i)
            if(v[i].second==v[(i+1)%n].second)
            {
                pos=i;
                break;
            }
        for(int i=0;i<n;++i)
            cout<<v[(i+pos)%n].first<<" ";
        cout<<'\n';
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3620kb

input:

3
001
000
100
4
0000
0000
0000
0000

output:

1 2 3 
1 2 4 3 

result:

ok 2 cases.

Test #2:

score: 0
Accepted
time: 3ms
memory: 3576kb

input:

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

output:

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

result:

ok 4 cases.

Test #3:

score: -100
Wrong Answer
time: 3ms
memory: 3544kb

input:

4
0000
0000
0000
0000
4
0000
0001
0000
0100
4
0100
1010
0100
0000
4
0111
1000
1000
1000
4
0010
0011
1101
0110
4
0111
1011
1100
1100
4
0111
1011
1101
1110
4
0000
0011
0101
0110
4
0101
1010
0100
1000
4
0011
0011
1100
1100
4
0010
0001
1000
0100

output:

1 2 4 3 
2 3 1 4 
2 4 3 1 
4 2 3 1 
4 2 3 1 
1 2 4 3 
1 2 4 3 
4 2 3 1 
2 4 3 1 
1 4 2 3 
4 1 2 3 

result:

wrong answer case #6: found 2 indices