QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#196296 | #2833. Hamilton | CSU2023# | WA | 0ms | 3912kb | C++14 | 1.3kb | 2023-10-01 15:25:15 | 2023-10-01 15:25:15 |
Judging History
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