QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#196296#2833. HamiltonCSU2023#WA 0ms3912kbC++141.3kb2023-10-01 15:25:152023-10-01 15:25:15

Judging History

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

  • [2023-10-01 15:25:15]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3912kb
  • [2023-10-01 15:25:15]
  • 提交

answer

#include <bits/stdc++.h>

using std::ios;
using std::cin;
using std::cout;

const int N = 2005;
char c[N][N];
int n, p[N];

int main()
{
    //freopen("g.in", "r", stdin);
    while (scanf("%d", &n) != EOF)
    {
        for (int i = 1; i <= n; ++i)
            scanf("%s", c[i] + 1);
        bool allsame = true;
        p[1] = 1; p[2] = 2;
        for (int i = 3; i <= n; ++i)
        {
            if (allsame)
            {
                if (c[i][p[i - 1]] != c[p[1]][p[2]])
                    allsame = false;
                p[i] = i;
            }
            else
            {
                int j;
                for (j = 2; j + 1 < i; ++j)
                    if (c[p[j - 1]][p[j]] != c[p[j]][p[j + 1]])
                        break ;
                if (c[p[j]][i] == c[p[j]][p[j + 1]])
                {
                    p[i] = i;
                    for (int k = i - 1; k >= j; --k)
                        std::swap(p[k], p[k + 1]);
                }
                else
                {
                    p[i] = i;
                    for (int k = i - 1; k > j; --k)
                        std::swap(p[k], p[k + 1]);
                }
            }
        }
        for (int i = 1; i <= n; ++i)
            printf("%d ", p[i]);
        putchar('\n');
    }
    return 0;
}

详细

Test #1:

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

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: 3828kb

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