QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#56758 | #2833. Hamilton | indogent | AC ✓ | 39ms | 7164kb | C++ | 1.3kb | 2022-10-21 15:39:11 | 2022-10-21 15:39:13 |
Judging History
answer
#include <cstdio>
#include <cstdlib>
#include <vector>
const int N = 2000 + 10;
char s[N][N];
int main() {
int n;
while (scanf("%d", &n) == 1) {
for (int i = 0; i < n; ++i)
scanf("%s", s[i]);
std::vector<int> path = {0, 1, 2};
std::vector<char> col = {s[0][1], s[1][2], s[2][0]};
for (int i = 3; i < n; ++i) {
int x = 0, y = 1, z = 2;
for (size_t j = 0; j < path.size(); ++j) {
if (col[j] != col[(j + 1) % path.size()]) {
x = j;
y = (j + 1) % path.size();
z = (j + 2) % path.size();
break;
}
}
char t = s[i][path[y]];
if (t == col[x]) {
path.insert(path.begin() + z, i);
col[y] = col[x];
col.insert(col.begin() + z, s[i][path[z + 1]]);
} else {
path.insert(path.begin() + y, i);
col.insert(col.begin() + y, t);
col[x] = s[i][path[(y - 1 + path.size()) % path.size()]];
}
}
int x = 0;
for (size_t j = 0; j < path.size(); ++j) {
if (col[j] != col[(j + 1) % path.size()]) {
x = j;
break;
}
}
for (int i = 1; i <= n; ++i) {
printf("%d", path[(x + i) % n] + 1);
if (i == n)
puts("");
else
putchar(' ');
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3152kb
input:
3 001 000 100 4 0000 0000 0000 0000
output:
3 1 2 2 4 3 1
result:
ok 2 cases.
Test #2:
score: 0
Accepted
time: 2ms
memory: 3184kb
input:
3 000 000 000 3 010 100 000 3 011 100 100 3 011 101 110
output:
2 3 1 2 3 1 2 3 1 2 3 1
result:
ok 4 cases.
Test #3:
score: 0
Accepted
time: 2ms
memory: 3104kb
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:
2 4 3 1 4 2 3 1 2 4 3 1 4 2 3 1 4 2 3 1 4 3 1 2 2 4 3 1 4 2 3 1 2 4 3 1 4 2 3 1 1 2 3 4
result:
ok 11 cases.
Test #4:
score: 0
Accepted
time: 2ms
memory: 3204kb
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:
2 5 4 3 1 2 5 4 3 1 4 5 2 3 1 5 2 4 3 1 2 4 3 1 5 5 3 1 2 4 5 4 3 1 2 3 1 4 2 5 2 4 5 3 1 4 5 2 3 1 2 5 4 3 1 5 3 1 2 4 2 4 5 3 1 2 5 4 3 1 5 4 2 3 1 5 3 1 2 4 2 3 1 5 4 5 2 3 1 4 4 3 1 2 5 2 5 4 3 1 2 5 4 3 1 1 4 2 3 5 3 1 2 4 5 5 3 1 2 4 2 3 1 4 5 3 1 2 4 5 5 4 2 3 1 5 1 2 3 4 5 1 2 3 4 5 2 3 1 4 ...
result:
ok 34 cases.
Test #5:
score: 0
Accepted
time: 2ms
memory: 3156kb
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:
2 6 5 4 3 1 2 6 5 4 3 1 6 2 5 4 3 1 4 3 1 2 5 6 6 4 3 1 2 5 6 3 1 2 4 5 6 4 3 1 2 5 6 5 2 3 1 4 6 3 1 4 2 5 6 5 4 3 1 2 6 4 2 3 1 5 6 1 2 3 4 5 2 5 6 4 3 1 6 5 4 3 1 2 2 6 5 4 3 1 2 6 5 4 3 1 1 5 4 2 3 6 6 4 3 1 2 5 4 6 5 2 3 1 6 5 4 3 1 2 6 5 2 4 3 1 6 4 2 3 1 5 6 5 2 3 1 4 1 6 5 2 3 4 4 3 1 2 5 6 ...
result:
ok 156 cases.
Test #6:
score: 0
Accepted
time: 3ms
memory: 3232kb
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 2 3 1 5 6 4 3 4 5 1 6 2 7 7 6 4 2 3 5 1 7 5 6 4 3 1 2 7 5 6 3 1 2 4 1 4 2 3 5 6 7 6 7 5 4 3 1 2 4 7 5 2 6 3 1 7 3 1 2 5 4 6 4 5 2 3 1 6 7 7 5 4 3 1 2 6 1 2 5 4 6 3 7 7 2 4 3 5 1 6 1 7 6 5 2 3 4 5 7 6 2 3 1 4 7 6 5 4 3 1 2 7 5 4 2 3 1 6 4 3 1 7 2 6 5 5 7 4 2 3 1 6 5 6 7 4 2 3 1 7 2 4 3 1 5 6 5 7 6 ...
result:
ok 286 cases.
Test #7:
score: 0
Accepted
time: 0ms
memory: 3160kb
input:
5 01000 10100 01010 00100 00000 9 001101110 001010001 110100110 101010000 010100011 100000000 101000000 101010001 010010010 4 0000 0011 0101 0110 8 00100101 00101100 11000011 00001111 01010101 11011000 00110000 10111000 9 000000001 001101000 010000100 010000111 000000000 010000111 001101010 00010110...
output:
2 3 4 1 5 9 8 3 1 2 6 5 7 4 4 2 3 1 8 6 7 1 2 4 3 5 9 8 7 6 2 3 1 4 5 4 2 3 1 1 6 5 2 3 4 3 4 1 5 2 6 6 5 3 1 2 4 7 4 7 6 2 3 1 5 10 8 6 7 1 5 2 3 4 9 10 1 2 5 6 4 7 3 8 9 6 5 3 1 2 4 4 3 1 5 6 2 7 8 9 8 6 7 5 2 4 3 1 2 3 1 2 3 1 6 5 4 2 3 1 7 6 5 4 3 1 2 2 3 1 2 3 1 2 3 1 4 5 1 4 2 5 3 6 3 1 4 2 6 ...
result:
ok 322 cases.
Test #8:
score: 0
Accepted
time: 1ms
memory: 3204kb
input:
10 0010001000 0010011001 1101101001 0010111000 0011000110 0101001100 1111010001 0000110011 0000100101 0110001110 10 0000000010 0000001001 0000001101 0000100000 0001010111 0000101011 0110010100 0010101000 1000110000 0110110000 10 0110010111 1011111110 1100101010 0100001101 0110001111 1100001010 01111...
output:
7 10 9 8 6 4 3 1 2 5 10 6 5 4 3 1 2 8 9 7 9 4 3 1 2 6 7 5 8 10 4 10 2 9 5 8 6 7 3 1 10 8 7 6 2 3 1 4 5 9 10 8 9 4 2 3 1 5 6 7 1 5 4 2 6 7 8 9 3 10 7 10 9 8 6 5 4 3 1 2 9 10 5 2 3 1 4 6 7 8 10 9 8 5 6 4 3 1 2 7 8 7 5 4 2 3 6 9 1 10 9 10 1 2 3 4 8 7 6 5 6 10 7 9 8 2 5 4 3 1 10 8 3 4 1 5 2 6 7 9 10 8 9...
result:
ok 200 cases.
Test #9:
score: 0
Accepted
time: 3ms
memory: 3240kb
input:
10 0110101100 1010100111 1101100101 0010111010 1111001010 0001000000 1001100111 1110001001 0101101000 0110001100 10 0111110111 1001111100 1001100100 1110101111 1111001010 1100001000 0101110100 1111001010 1001100100 1001000000 10 0100000111 1011111001 0100001111 0100100110 0101011100 0100100110 01101...
output:
10 7 4 5 2 3 1 6 8 9 8 10 9 6 7 5 4 3 1 2 1 2 4 5 7 8 6 9 3 10 10 9 8 6 2 3 1 5 4 7 4 2 3 1 5 7 8 9 6 10 8 7 1 5 2 3 4 6 9 10 9 8 7 6 4 5 3 1 2 10 7 10 8 9 6 1 2 4 3 5 8 10 9 3 1 2 4 5 6 7 7 8 1 6 4 2 3 5 10 9 10 5 9 7 8 6 1 2 3 4 10 3 1 7 6 5 4 2 8 9 2 10 8 9 4 5 6 7 3 1 9 10 7 6 1 2 3 4 5 8 9 5 8 ...
result:
ok 200 cases.
Test #10:
score: 0
Accepted
time: 4ms
memory: 3248kb
input:
20 00011111000111100010 00100111111000000010 01011011101000100111 10100010000100000010 10100100000010101101 11001001010010000111 11110000010000111001 11100100111000010101 01100001011101100010 01000111100111011001 01100001100111111111 10010000111001010000 10001100011001001000 10000000111110111010 101...
output:
20 5 17 16 15 14 13 10 12 11 9 8 3 1 2 4 6 7 18 19 17 19 18 12 13 8 9 2 4 5 6 3 7 1 11 10 15 14 16 22 12 10 11 6 5 3 1 2 4 8 9 13 16 17 18 19 14 20 15 21 7 13 11 12 10 9 8 7 4 3 1 2 5 6 27 23 25 24 16 15 14 13 7 4 8 2 3 1 11 5 10 9 6 12 17 19 20 21 18 22 26 29 28 30 21 22 18 19 17 15 14 2 12 9 11 10...
result:
ok 72 cases.
Test #11:
score: 0
Accepted
time: 0ms
memory: 3336kb
input:
59 01110100011001000100111000110110010001011111001011011101100 10001011111001111100111111100010111011100101001100001000101 10000011101010011100111011000001101110001100001110110101001 10001100100110101001000000101101101110001110111001110001101 010101010101101111110011111000100101111111101001111100111...
output:
59 58 56 48 55 54 53 52 51 47 46 45 44 43 42 36 41 40 38 39 37 31 34 33 32 29 28 24 23 22 20 7 19 18 11 17 12 16 13 15 14 9 10 6 2 3 1 4 5 8 21 25 26 27 30 35 49 50 57 58 63 62 57 56 54 50 47 49 48 46 39 45 41 44 43 42 38 36 25 35 34 28 33 32 31 30 29 27 26 16 13 15 14 11 5 10 9 8 6 7 3 1 2 4 12 18 ...
result:
ok 29 cases.
Test #12:
score: 0
Accepted
time: 2ms
memory: 3532kb
input:
160 0010110100011110110110110001100110111000000100001100110101001011100101011100011100111011011011010011010110101100000011111010110111001011001100010000101111001101 000011011110000111010100011011010001001101001100111010101101001011001101001001000001011010001101100111011110110101111010101100000101001...
output:
160 154 116 113 91 88 79 80 78 77 76 75 74 72 71 69 68 66 65 56 64 61 63 62 51 53 52 49 48 46 41 39 40 36 33 32 27 26 25 24 22 19 21 20 17 8 16 13 15 14 2 12 9 11 10 3 4 7 6 5 1 18 23 29 30 31 28 34 35 37 38 42 44 43 45 47 50 54 55 57 58 59 60 67 70 73 82 83 84 85 86 81 87 89 90 92 96 95 97 101 102 ...
result:
ok 14 cases.
Test #13:
score: 0
Accepted
time: 9ms
memory: 5592kb
input:
438 01000100111101110010100101010001000101100011101011001001011110011100000110001001100101100101110011110111001101001101100111110010011001000110100110101001001101110001110011101010100010110100001011110011001000000001111111011001001010011101110010110111011111100011111101101001101010101010110000000111...
output:
438 428 437 436 426 391 406 399 405 404 403 400 402 401 398 397 394 396 395 393 392 390 389 380 388 387 386 381 385 383 384 382 377 375 376 374 373 372 369 371 370 368 365 345 364 354 363 362 359 361 360 357 358 356 355 348 353 351 352 350 349 347 346 344 340 341 338 337 332 330 329 320 326 325 298 ...
result:
ok 7 cases.
Test #14:
score: 0
Accepted
time: 8ms
memory: 5564kb
input:
1227 0100010000101001111110111010100100001100101111001011101010010000100111110110000001101101000101010011000101100110010011010100010011111000101101011001010111010010101001100100011000100000101011011011110101010011011110111101110010100010101111010101011001100001000110011101101010010011110010011011100...
output:
1225 1227 1226 1202 1210 1203 1209 1208 1207 1206 1205 1204 1199 1181 1198 1197 1196 1195 1182 1194 1189 1193 1192 1191 1190 1188 1184 1187 1183 1186 1185 1177 1170 1169 1161 1168 1164 1167 1165 1166 1163 1162 1155 1160 1159 1156 1158 1157 1149 1148 1146 1145 1144 1143 1140 1142 1141 1136 1130 1129 ...
result:
ok 2 cases.
Test #15:
score: 0
Accepted
time: 13ms
memory: 5620kb
input:
1078 0111011100111011000000110100010011001100100101011100111000110001110111110010111010110111010110001010100111101001110111010010000001000100110000000010000010111010101000000110101011011011000001100000011111010001010001101111011110111110000110111111111111101100110100011001110110111011111001110010110...
output:
1078 1076 1073 1072 1071 1070 1066 1065 1061 1062 1058 1057 1051 1048 1046 1045 1044 1043 1032 1036 1035 1024 1023 1017 1019 1018 1015 1012 1014 1013 1008 1006 1005 1004 1003 990 997 996 995 994 993 988 987 985 986 982 975 974 973 972 970 967 969 968 964 963 962 959 961 960 958 951 947 944 946 945 9...
result:
ok 2 cases.
Test #16:
score: 0
Accepted
time: 10ms
memory: 6596kb
input:
1310 0110101010101111001001001110010101000100000000011001001110111010011000110110010000001110111100110100110110110000011001000101100100000011011111011100010001101111001100100000011100111111101101001011000101000011100101111011100101011111000100101110011110001101110110100111101101011000000000101000101...
output:
1310 1306 1309 1308 1307 1304 1303 1302 1295 1294 1292 1293 1291 1288 1290 1289 1286 1281 1280 1279 1278 1273 1274 1270 1265 1266 1262 1261 1257 1254 1238 1237 1236 1232 1229 1231 1230 1227 1221 1218 1219 1216 1213 1211 1210 1208 1209 1207 1198 1206 1201 1205 1204 1202 1203 1200 1199 1190 1187 1172 ...
result:
ok 2 cases.
Test #17:
score: 0
Accepted
time: 19ms
memory: 6268kb
input:
1542 0000100001001001100011001101100001110111010111001110111110011011001000110010001111000000100011101001000100000001111001110100110101101111000011100010000100000111010001010110101110000001000001110100101111100001110010111000111001010111011100100100111011010101001100100101110110011000001011001000011...
output:
1542 1510 1540 1539 1538 1537 1522 1536 1523 1535 1534 1533 1532 1531 1530 1524 1529 1528 1527 1526 1525 1519 1521 1520 1513 1518 1516 1517 1515 1514 1511 1512 1509 1508 1503 1507 1505 1506 1502 1500 1499 1495 1491 1494 1480 1493 1492 1482 1481 1479 1478 1477 1475 1469 1474 1471 1473 1472 1470 1467 ...
result:
ok 2 cases.
Test #18:
score: 0
Accepted
time: 22ms
memory: 7144kb
input:
2000 0101010000001001011001110100110110001010001110110101101100010010011100000111001100000000110111011111100001110001111011101101110010100100001001110010001111011110011011010000100001011100000000110011000110010100101010110100001010101001111101011001110011010001100110000110101110000001000101001101010...
output:
2000 1996 1980 1979 1978 1974 1977 1970 1976 1975 1966 1969 1968 1967 1963 1962 1957 1952 1956 1955 1954 1953 1945 1951 1950 1947 1949 1948 1941 1944 1942 1943 1940 1936 1927 1914 1902 1895 1901 1900 1899 1898 1897 1896 1894 1891 1893 1892 1888 1890 1889 1885 1886 1880 1876 1874 1871 1873 1872 1870 ...
result:
ok 1 cases.
Test #19:
score: 0
Accepted
time: 22ms
memory: 7124kb
input:
2000 0100001100010101000111011110110000001010100001111010011110111010011101000001100111011101101100000100100011001100011101011110101011101000010000000001010110001100011111100011010110101010001100011100011100000111011011100010110010100001111101011001010111111101011100111011110001101000111100110101000...
output:
2000 1998 1999 1996 1994 1995 1986 1983 1982 1977 1975 1967 1969 1968 1964 1963 1962 1961 1960 1948 1954 1951 1953 1952 1949 1950 1945 1942 1935 1907 1925 1924 1923 1908 1922 1919 1921 1920 1918 1917 1916 1915 1914 1912 1913 1911 1909 1910 1904 1887 1886 1884 1876 1870 1853 1858 1855 1857 1856 1854 ...
result:
ok 1 cases.
Test #20:
score: 0
Accepted
time: 39ms
memory: 7104kb
input:
2000 0110101010100011101110010101000111001011110000101111001110111111100111000101010001110111000110110001010000010101101001011001111111011111111111011111000011100001111110000101100100000110100100100110110010000101101101100100001101100010011100000011110000100100011110111001101001101100110111011101011...
output:
1989 1990 1988 1984 1983 1982 1981 1980 1979 1974 1978 1976 1977 1975 1939 1937 1936 1935 1934 1932 1929 1931 1930 1928 1923 1927 1926 1922 1919 1907 1918 1908 1917 1909 1916 1910 1915 1902 1914 1913 1912 1911 1899 1898 1888 1886 1884 1881 1870 1869 1868 1863 1867 1865 1866 1862 1860 1861 1854 1844 ...
result:
ok 1 cases.
Test #21:
score: 0
Accepted
time: 17ms
memory: 7164kb
input:
2000 0110000110000000010000010011101111110001110101010000000001101110101010101001111001010100100101001100010100101000110001000101000101010011011000000100011110100001000010000111100110111010110001000100011100100011111001011011111011111001101101111011111011111010011100001111010001011101110000000001011...
output:
1997 1994 1989 1992 1991 1990 1975 1974 1973 1971 1965 1970 1969 1968 1967 1966 1964 1963 1953 1952 1950 1949 1940 1937 1939 1938 1927 1935 1934 1933 1928 1932 1931 1930 1929 1924 1923 1922 1919 1918 1917 1910 1912 1911 1909 1908 1907 1905 1906 1903 1901 1900 1899 1896 1895 1894 1892 1886 1885 1882 ...
result:
ok 1 cases.
Test #22:
score: 0
Accepted
time: 29ms
memory: 7104kb
input:
2000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
2 2000 1999 1998 1997 1996 1995 1994 1993 1992 1991 1990 1989 1988 1987 1986 1985 1984 1983 1982 1981 1980 1979 1978 1977 1976 1975 1974 1973 1972 1971 1970 1969 1968 1967 1966 1965 1964 1963 1962 1961 1960 1959 1958 1957 1956 1955 1954 1953 1952 1951 1950 1949 1948 1947 1946 1945 1944 1943 1942 194...
result:
ok 1 cases.
Test #23:
score: 0
Accepted
time: 23ms
memory: 7088kb
input:
2000 0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
2 2000 1999 1998 1997 1996 1995 1994 1993 1992 1991 1990 1989 1988 1987 1986 1985 1984 1983 1982 1981 1980 1979 1978 1977 1976 1975 1974 1973 1972 1971 1970 1969 1968 1967 1966 1965 1964 1963 1962 1961 1960 1959 1958 1957 1956 1955 1954 1953 1952 1951 1950 1949 1948 1947 1946 1945 1944 1943 1942 194...
result:
ok 1 cases.