QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#196304 | #2833. Hamilton | CSU2023# | WA | 0ms | 3820kb | C++14 | 1.5kb | 2023-10-01 15:35:21 | 2023-10-01 15:35:22 |
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]);
}
}
}
if (c[p[1]][p[2]] == c[p[n]][p[1]])
{
int temp = p[n];
for (int i = n - 1; i >= 1; --i)
p[i + 1] = p[i];
p[1] = temp;
}
for (int i = 1; i <= n; ++i)
printf("%d ", p[i]);
putchar('\n');
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3768kb
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: 0ms
memory: 3772kb
input:
3 000 000 000 3 010 100 000 3 011 100 100 3 011 101 110
output:
3 1 2 1 2 3 3 1 2 3 1 2
result:
ok 4 cases.
Test #3:
score: 0
Accepted
time: 0ms
memory: 3820kb
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 2 3 4 3 1 4 2 1 4 2 3 4 1 2 3 4 1 2 3 3 1 4 2 4 1 2 3 3 1 4 2 4 1 2 3
result:
ok 11 cases.
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3768kb
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 3 1 2 5 4 1 2 5 3 4 1 2 3 5 4 3 1 4 2 5 5 1 2 3 4 3 1 2 4 5 3 1 2 4 5 3 1 2 4 5 3 1 5 4 2 3 1 2 4 5 1 2 3 4 5 1 2 3 5 4 1 2 5 3 4 1 2 5 4 3 1 2 3 5 4 1 4 2 5 3 1 2 4 5 3 4 1 2 5 3 1 4 5 2 3 1 2 3 5 4 5 1 2 3 4 1 2...
result:
wrong answer case #22: found 3 indices