QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377700#2833. HamiltonJerrywangWA 1ms4084kbC++141.6kb2024-04-05 16:49:462024-04-05 16:49:46

Judging History

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

  • [2024-04-05 16:49:46]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4084kb
  • [2024-04-05 16:49:46]
  • 提交

answer

// Title:  Hamilton
// Source: QOJ2833
// Author: Jerrywang
#include <bits/stdc++.h>
#define F first
#define S second
#define pii pair<int, int>
#define ll long long
#define rep(i, s, t) for(int i=s; i<=t; ++i)
#define debug(x) cerr<<#x<<":"<<x<<endl;
const int N=2005;
using namespace std;

int n, g[N][N]; vector<int> a;
void ins(int i, int x)
{
    a.insert(a.begin()+i, x);
}
bool getans(int val)
{
    a.clear();
    rep(i, 1, n)
    {
        bool f=0;
        rep(j, i+1, n) if(g[i][j]==val)
        {
            a.push_back(i), a.push_back(j), f=1; break;
        }
        if(f) break;
    }
    if(a.empty()) return 0;
    rep(i, 1, n)
    {
        int k=-1;
        for(int x:a) if(x==i) k=1;
        if(k==1) continue;
        rep(j, 1, a.size()-2)
        {
            if(g[a[j-1]][a[j]]==val && g[a[j]][a[j+1]]!=val)
            {
                k=j; break;
            }
        }
        if(k==-1) a.push_back(i);
        else if(g[a[k]][i]==val) ins(k+1, i);
        else ins(k, i);
    }
    if(g[a[n-1]][a[0]]==val)
        a.insert(a.begin(), a[n-1]), a.pop_back();
    vector<int> c(n);
    rep(i, 0, a.size()-1) c[i]=(g[a[i]][a[(i+1)%n]]);
    int cnt=0;
    rep(i, 0, n-2) cnt+=(c[i]!=c[i+1]);
    if(cnt>1) return 0;
    for(int x:a) printf("%d ", x);
    puts(""); return 1;
}
void solve()
{
    rep(i, 1, n) rep(j, 1, n) scanf("%1d", &g[i][j]);
    if(!getans(0)) getans(1);
}
int main()
{
    #ifdef Jerrywang
    freopen("E:/OI/in.txt", "r", stdin);
    #endif
    while(~scanf("%d", &n)) solve();
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4084kb

input:

3
001
000
100
4
0000
0000
0000
0000

output:

1 2 3 
4 1 2 3 

result:

ok 2 cases.

Test #2:

score: 0
Accepted
time: 1ms
memory: 3760kb

input:

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

output:

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

result:

ok 4 cases.

Test #3:

score: 0
Accepted
time: 1ms
memory: 3780kb

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:

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

result:

ok 11 cases.

Test #4:

score: 0
Accepted
time: 1ms
memory: 3784kb

input:

5
00000
00000
00000
00000
00000
5
00001
00000
00000
00000
10000
5
00010
00010
00000
11000
00000
5
00000
00001
00001
00001
01110
5
00001
00001
00001
00001
11110
5
00101
00100
11011
00100
10100
5
01111
10011
10000
11000
11000
5
00011
00011
00011
11101
11110
5
01101
10111
11001
01001
11110
5
00111
0011...

output:

5 1 2 3 4 
1 2 3 4 5 
5 1 2 3 4 
5 1 2 3 4 
1 2 3 4 5 
1 2 4 5 3 
2 3 4 5 1 
1 2 5 3 4 
1 4 5 3 2 
1 4 2 3 5 
5 1 2 3 4 
2 3 5 4 1 
1 4 3 2 5 
1 3 5 2 4 
2 4 5 3 1 
3 1 2 4 5 
1 5 2 4 3 
1 4 5 2 3 
1 2 5 3 4 
1 2 5 4 3 
1 2 3 5 4 
1 4 2 3 5 
1 2 4 5 3 
4 1 2 5 3 
5 1 3 2 4 
1 3 5 4 2 
5 1 2 3 4 
1 2...

result:

ok 34 cases.

Test #5:

score: 0
Accepted
time: 1ms
memory: 3756kb

input:

6
000000
000000
000000
000000
000000
000000
6
000000
000000
000001
000000
000000
001000
6
010000
100100
000000
010000
000000
000000
6
000100
000000
000100
101010
000100
000000
6
000100
000000
000100
101011
000100
000100
6
001000
001000
110111
001000
001000
001000
6
001100
000100
100100
111011
000100...

output:

6 1 2 3 4 5 
6 1 2 3 4 5 
6 1 3 2 5 4 
1 2 3 5 6 4 
1 2 3 5 6 4 
1 2 4 5 6 3 
1 2 3 5 6 4 
1 2 5 6 3 4 
1 4 2 5 6 3 
1 2 6 5 4 3 
6 1 5 4 2 3 
6 1 5 4 3 2 
1 3 4 2 5 6 
3 2 6 1 4 5 
4 2 6 1 3 5 
6 1 2 3 4 5 
1 5 4 2 3 6 
1 2 3 6 4 5 
6 1 3 2 4 5 
4 1 2 3 6 5 
5 1 2 3 6 4 
2 4 6 5 3 1 
1 4 6 5 2 3 
1...

result:

ok 156 cases.

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 3812kb

input:

7
0000010
0001011
0001010
0110100
0001001
1110001
0100110
7
0101001
1011000
0101100
1110010
0010010
0001100
1000000
7
0001111
0011001
0100100
1100101
1011000
1000000
1101000
7
0111111
1011101
1101001
1110010
1100010
1001101
1110010
7
0010111
0010001
1101010
0010000
1000011
1010100
1100100
7
0001010
...

output:

7 1 2 3 5 6 4 
7 1 2 3 4 6 5 
6 1 4 2 3 7 5 
2 5 6 4 3 1 7 
1 2 4 5 3 7 6 
6 1 4 2 3 7 5 
3 1 2 6 7 5 4 
7 1 4 5 2 6 3 
1 2 5 6 7 3 4 
1 2 3 5 4 6 7 
3 1 2 6 7 5 4 
1 3 4 2 7 6 5 
7 1 2 4 3 5 6 
7 1 2 3 4 5 6 
2 6 7 5 4 3 1 
4 1 2 3 7 6 5 
6 1 3 2 4 7 5 
6 1 2 4 3 7 5 
5 1 3 2 4 6 7 
1 3 2 4 5 6 7 
...

result:

wrong answer case #235: found 4 indices