QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#21906 | #2833. Hamilton | DaBenZhongXiaSongKuaiDi# | AC ✓ | 107ms | 7712kb | C++14 | 1.3kb | 2022-03-08 17:17:09 | 2022-05-08 04:14:20 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
char e[2005][2005];
vector <int> v;
signed main(int argc, char** argv) {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
while(cin >> n)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
cin >> e[i][j];
}
v.clear();
v.push_back(1);
v.push_back(2);
v.push_back(3);
for(int i=4;i<=n;i++)
{
int mn=1e9,pos=0,N=v.size();
for(int j=0;j<N;j++)
{
int w=0;
if(e[v[(j-1+N)%N]][v[j]]!=e[v[j]][v[(j+1)%N]]) --w;
if(e[v[j]][v[(j+1)%N]]!=e[v[(j+1)%N]][v[(j+2)%N]]) --w;
if(e[v[(j-1+N)%N]][v[j]]!=e[v[j]][i]) ++w;
if(e[v[j]][i]!=e[i][v[(j+1)%N]]) ++w;
if(e[i][v[(j+1)%N]]!=e[v[(j+1)%N]][v[(j+2)%N]]) ++w;
if(w<mn) mn=w,pos=j;
}
vector <int> nxt;
for(int i=0;i<=pos;i++) nxt.push_back(v[i]);
nxt.push_back(i);
for(int i=pos+1;i<N;i++) nxt.push_back(v[i]);
swap(nxt,v);
}
int flag=0;
for(int j=0;j<n;j++)
{
if(e[v[j]][v[(j+1)%v.size()]]!=e[v[(j-1+v.size())%v.size()]][v[j]])
{
for(int i=j;i<v.size();i++)
cout << v[i] << " ";
for(int i=0;i<j;i++)
cout << v[i] << " ";
cout << "\n";
flag=1;
break;
}
}
if(!flag)
{
for(auto t:v) cout << t << " ";
cout << "\n";
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 3568kb
input:
3 001 000 100 4 0000 0000 0000 0000
output:
1 2 3 1 4 2 3
result:
ok 2 cases.
Test #2:
score: 0
Accepted
time: 2ms
memory: 3652kb
input:
3 000 000 000 3 010 100 000 3 011 100 100 3 011 101 110
output:
1 2 3 1 2 3 2 3 1 1 2 3
result:
ok 4 cases.
Test #3:
score: 0
Accepted
time: 0ms
memory: 3572kb
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:
1 4 2 3 1 2 3 4 2 3 1 4 4 2 3 1 1 4 2 3 1 4 2 3 1 4 2 3 4 2 3 1 1 2 4 3 1 4 2 3 1 2 3 4
result:
ok 11 cases.
Test #4:
score: 0
Accepted
time: 3ms
memory: 3520kb
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:
1 5 4 2 3 1 4 5 2 3 4 2 3 1 5 5 4 2 3 1 1 5 4 2 3 5 4 2 3 1 5 3 1 4 2 1 5 4 2 3 1 5 4 2 3 1 5 4 2 3 1 5 4 2 3 2 3 1 5 4 1 2 4 5 3 1 2 5 4 3 5 4 2 3 1 2 3 1 5 4 1 5 2 3 4 5 4 2 3 1 4 5 2 3 1 1 4 5 2 3 1 5 4 2 3 1 4 2 3 5 1 5 4 2 3 1 5 4 2 3 5 4 2 3 1 1 5 4 2 3 5 2 3 4 1 1 5...
result:
ok 34 cases.
Test #5:
score: 0
Accepted
time: 0ms
memory: 3528kb
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:
1 6 5 4 2 3 1 6 5 4 2 3 1 6 4 5 2 3 1 5 6 4 2 3 5 4 2 3 1 6 1 6 5 4 2 3 6 5 2 3 1 4 5 4 2 3 1 6 6 5 4 2 3 1 6 4 2 3 1 5 1 6 5 4 2 3 6 5 4 2 3 1 1 6 5 2 4 3 1 5 4 6 2 3 1 6 5 4 2 3 1 6 5 4 2 3 1 5 4 2 3 6 1 4 2 6 5 3 1 6 5 4 2 3 1 6 4 2 5 3 6 4 2 3 5 1 5 4 2 3 1 6 5 4 2 3 1 6 1...
result:
ok 156 cases.
Test #6:
score: 0
Accepted
time: 0ms
memory: 3672kb
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 7 5 2 6 3 4 1 7 6 4 2 3 5 1 1 5 6 4 2 7 3 7 4 2 3 1 6 5 6 4 2 3 1 7 5 1 7 6 4 5 2 3 1 7 4 5 2 6 3 1 7 6 4 5 2 3 1 7 6 4 5 2 3 2 5 4 3 1 6 7 7 6 4 5 2 3 1 1 7 6 5 4 2 3 1 7 6 5 4 2 3 7 2 3 1 6 5 4 7 6 4 2 5 3 1 1 5 4 2 3 6 7 7 5 2 4 3 1 6 1 4 7 6 2 5 3 1 6 7 5 4 2 3 ...
result:
ok 286 cases.
Test #7:
score: 0
Accepted
time: 3ms
memory: 3588kb
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:
1 4 2 5 3 9 7 6 4 5 2 3 1 8 4 2 3 1 8 7 6 4 5 2 3 1 9 8 7 4 2 3 1 6 5 1 4 2 3 6 2 3 1 5 4 1 6 4 2 5 3 7 5 4 2 3 1 6 1 5 4 7 6 2 3 1 8 7 10 6 9 5 2 3 4 1 7 4 6 9 5 10 2 3 8 1 5 4 2 3 6 8 4 2 5 7 3 6 1 9 2 3 1 7 5 4 8 6 1 2 3 1 2 3 1 6 5 4 2 3 4 2 3 1 6 7 5 1 2 3 1 2 3 2 3 1 4 5 ...
result:
ok 322 cases.
Test #8:
score: 0
Accepted
time: 2ms
memory: 3744kb
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:
1 9 7 8 4 2 5 10 6 3 7 6 4 2 5 3 1 10 8 9 1 10 9 6 7 5 8 4 2 3 8 10 6 5 4 2 3 1 7 9 10 6 5 7 4 2 3 1 9 8 8 7 6 5 4 2 3 1 9 10 1 10 9 8 7 6 5 4 2 3 10 9 6 7 5 2 4 3 8 1 6 5 2 3 1 9 4 8 10 7 1 6 7 5 8 10 9 2 4 3 1 10 8 7 5 9 4 2 3 6 8 10 7 5 4 2 3 1 9 6 8 6 7 4 2 3 1 10 5 9 1 8 6 9 10 5 4...
result:
ok 200 cases.
Test #9:
score: 0
Accepted
time: 2ms
memory: 3584kb
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:
6 2 3 1 8 10 7 9 5 4 10 6 7 5 2 8 9 4 3 1 8 6 5 4 2 3 1 7 10 9 6 5 8 4 7 2 3 1 9 10 1 9 8 10 7 6 4 2 5 3 10 6 5 2 3 4 1 8 9 7 10 8 7 6 5 4 2 3 1 9 10 9 7 6 8 4 5 2 3 1 1 7 8 9 4 6 5 10 2 3 1 6 4 10 8 2 9 3 7 5 9 7 5 2 3 1 10 8 4 6 1 10 9 8 7 6 5 4 2 3 1 4 5 6 7 9 8 2 10 3 7 9 8 5 2 3 4 ...
result:
ok 200 cases.
Test #10:
score: 0
Accepted
time: 5ms
memory: 5784kb
input:
20 00011111000111100010 00100111111000000010 01011011101000100111 10100010000100000010 10100100000010101101 11001001010010000111 11110000010000111001 11100100111000010101 01100001011101100010 01000111100111011001 01100001100111111111 10010000111001010000 10001100011001001000 10000000111110111010 101...
output:
20 17 16 15 14 12 11 9 10 7 2 13 8 5 4 6 3 1 18 19 19 12 14 7 6 8 5 9 4 10 11 2 3 1 15 13 18 17 16 13 11 12 7 5 3 1 21 20 22 17 18 16 15 10 2 6 19 4 8 9 14 7 6 5 2 4 3 1 11 13 12 8 10 9 17 28 22 12 7 11 5 10 9 6 4 2 3 1 27 25 29 23 26 30 16 24 20 18 19 14 15 13 8 21 1 18 21 16 20 13 10 15 12 14...
result:
ok 72 cases.
Test #11:
score: 0
Accepted
time: 7ms
memory: 3908kb
input:
59 01110100011001000100111000110110010001011111001011011101100 10001011111001111100111111100010111011100101001100001000101 10000011101010011100111011000001101110001100001110110101001 10001100100110101001000000101101101110001110111001110001101 010101010101101111110011111000100101111111101001111100111...
output:
1 57 56 54 59 52 44 53 48 42 58 38 31 45 55 36 33 37 51 35 46 50 30 41 34 49 39 28 47 6 32 24 27 25 26 16 20 15 9 23 29 40 21 43 18 13 19 17 4 12 5 10 8 14 11 22 2 7 3 10 19 18 6 5 4 7 2 3 1 63 61 53 59 58 57 62 56 49 51 55 54 48 60 52 46 47 45 39 44 43 42 50 38 40 36 33 41 34 35 30 31 29 17 21 27 ...
result:
ok 29 cases.
Test #12:
score: 0
Accepted
time: 4ms
memory: 5796kb
input:
160 0010110100011110110110110001100110111000000100001100110101001011100101011100011100111011011011010011010110101100000011111010110111001011001100010000101111001101 000011011110000111010100011011010001001101001100111010101101001011001101001001000001011010001101100111011110110101111010101100000101001...
output:
12 24 14 21 15 19 13 10 9 8 7 6 2 3 5 4 1 156 150 160 148 154 153 149 159 157 155 158 143 151 142 141 138 152 137 132 147 145 131 139 146 114 130 135 144 140 119 133 128 127 120 122 126 124 125 113 116 123 111 108 134 118 129 121 117 112 115 110 103 136 101 107 95 109 99 104 106 92 105 89 96 98 82 1...
result:
ok 14 cases.
Test #13:
score: 0
Accepted
time: 15ms
memory: 4440kb
input:
438 01000100111101110010100101010001000101100011101011001001011110011100000110001001100101100101110011110111001101001101100111110010011001000110100110101001001101110001110011101010100010110100001011110011001000000001111111011001001010011101110010110111011111100011111101101001101010101010110000000111...
output:
23 19 13 17 16 15 14 11 9 12 4 10 5 7 6 8 2 3 1 432 435 438 436 430 431 426 434 429 427 437 433 423 420 410 417 419 428 425 424 415 421 413 403 414 412 418 408 399 422 404 407 406 401 400 409 416 411 397 405 391 396 398 381 380 379 374 390 395 394 375 388 402 393 368 392 383 386 377 389 373 385 387 ...
result:
ok 7 cases.
Test #14:
score: 0
Accepted
time: 54ms
memory: 7024kb
input:
1227 0100010000101001111110111010100100001100101111001011101010010000100111110110000001101101000101010011000101100110010011010100010011111000101101011001010111010010101001100100011000100000101011011011110101010011011110111101110010100010101111010101011001100001000110011101101010010011110010011011100...
output:
11 7 6 2 3 1 1225 1222 1226 1227 1214 1224 1220 1207 1221 1219 1216 1213 1215 1212 1210 1218 1209 1217 1208 1223 1211 1206 1191 1203 1187 1197 1196 1199 1204 1205 1202 1200 1184 1201 1198 1195 1186 1193 1192 1185 1190 1194 1189 1181 1180 1183 1188 1182 1176 1173 1178 1179 1168 1163 1169 1177 1174 11...
result:
ok 2 cases.
Test #15:
score: 0
Accepted
time: 49ms
memory: 6540kb
input:
1078 0111011100111011000000110100010011001100100101011100111000110001110111110010111010110111010110001010100111101001110111010010000001000100110000000010000010111010101000000110101011011011000001100000011111010001010001101111011110111110000110111111111111101100110100011001110110111011111001110010110...
output:
1 1077 1074 1078 1064 1059 1072 1076 1071 1067 1066 1062 1075 1073 1057 1070 1068 1058 1069 1040 1056 1063 1052 1047 1060 1046 1054 1061 1048 1055 1051 1053 1049 1038 1045 1065 1035 1050 1041 1028 1029 1033 1020 1037 1036 1025 1044 1031 1042 1030 1026 1039 1016 1015 1017 1032 1043 1022 1019 1027 102...
result:
ok 2 cases.
Test #16:
score: 0
Accepted
time: 45ms
memory: 6200kb
input:
1310 0110101010101111001001001110010101000100000000011001001110111010011000110110010000001110111100110100110110110000011001000101100100000011011111011100010001101111001100100000011100111111101101001011000101000011100101111011100101011111000100101110011110001101110110100111101101011000000000101000101...
output:
23 20 11 6 5 4 2 3 1 1310 1308 1309 1307 1305 1303 1297 1299 1301 1304 1294 1296 1291 1302 1300 1293 1290 1306 1289 1275 1295 1268 1282 1288 1292 1279 1298 1287 1286 1281 1280 1278 1283 1272 1274 1276 1284 1263 1270 1262 1277 1273 1285 1267 1257 1265 1266 1260 1258 1269 1264 1271 1249 1259 1261 1254...
result:
ok 2 cases.
Test #17:
score: 0
Accepted
time: 59ms
memory: 7152kb
input:
1542 0000100001001001100011001101100001110111010111001110111110011011001000110010001111000000100011101001000100000001111001110100110101101111000011100010000100000111010001010110101110000001000001110100101111100001110010111000111001010111011100100100111011010101001100100101110110011000001011001000011...
output:
10 17 5 4 2 3 1 1539 1541 1538 1535 1540 1534 1537 1536 1524 1542 1533 1532 1531 1530 1522 1521 1501 1526 1523 1529 1519 1528 1527 1525 1512 1487 1518 1516 1517 1520 1509 1508 1502 1510 1506 1514 1515 1511 1503 1507 1497 1505 1500 1495 1491 1504 1492 1513 1493 1496 1499 1482 1481 1479 1485 1494 1478...
result:
ok 2 cases.
Test #18:
score: 0
Accepted
time: 105ms
memory: 7536kb
input:
2000 0101010000001001011001110100110110001010001110110101101100010010011100000111001100000000110111011111100001110001111011101101110010100100001001110010001111011110011011010000100001011100000000110011000110010100101010110100001010101001111101011001110011010001100110000110101110000001000101001101010...
output:
6 10 7 4 2 3 1 1998 1999 1996 2000 1991 1984 1993 1987 1995 1997 1981 1992 1986 1985 1994 1990 1988 1980 1989 1982 1983 1979 1977 1976 1972 1969 1975 1965 1967 1970 1973 1978 1971 1974 1958 1961 1968 1957 1962 1963 1966 1964 1954 1955 1959 1956 1953 1951 1950 1949 1948 1944 1945 1952 1941 1947 1940 ...
result:
ok 1 cases.
Test #19:
score: 0
Accepted
time: 107ms
memory: 7632kb
input:
2000 0100001100010101000111011110110000001010100001111010011110111010011101000001100111011101101100000100100011001100011101011110101011101000010000000001010110001100011111100011010110101010001100011100011100000111011011100010110010100001111101011001010111111101011100111011110001101000111100110101000...
output:
13 14 12 11 10 9 6 4 2 7 5 8 3 1 1988 1996 2000 1995 1999 1997 1989 1993 1998 1992 1982 1991 1985 1975 1979 1994 1983 1987 1980 1990 1981 1966 1986 1984 1977 1976 1978 1964 1974 1960 1963 1968 1972 1947 1967 1965 1973 1971 1961 1949 1958 1970 1969 1959 1957 1962 1944 1956 1955 1952 1950 1942 1951 19...
result:
ok 1 cases.
Test #20:
score: 0
Accepted
time: 99ms
memory: 7712kb
input:
2000 0110101010100011101110010101000111001011110000101111001110111111100111000101010001110111000110110001010000010101101001011001111111011111111111011111000011100001111110000101100100000110100100100110110010000101101101100100001101100010011100000011110000100100011110111001101001101100110111011101011...
output:
18 17 16 15 14 12 11 10 13 2 8 4 5 7 9 6 3 1 1997 1991 1999 1994 1998 1987 2000 1990 1977 1996 1995 1988 1989 1966 1979 1985 1981 1976 1986 1974 1992 1993 1980 1968 1972 1978 1971 1967 1983 1955 1970 1958 1969 1965 1982 1984 1973 1944 1975 1963 1962 1961 1956 1964 1957 1946 1954 1943 1949 1953 1959 ...
result:
ok 1 cases.
Test #21:
score: 0
Accepted
time: 100ms
memory: 7684kb
input:
2000 0110000110000000010000010011101111110001110101010000000001101110101010101001111001010100100101001100010100101000110001000101000101010011011000000100011110100001000010000111100110111010110001000100011100100011111001011011111011111001101101111011111011111010011100001111010001011101110000000001011...
output:
1 1995 1997 1998 1987 1994 1986 1999 1991 1993 1985 1983 1984 1990 1996 1989 2000 1992 1988 1978 1981 1975 1982 1974 1973 1971 1977 1980 1972 1970 1960 1950 1979 1968 1976 1964 1967 1966 1963 1965 1952 1962 1955 1959 1957 1948 1961 1954 1969 1958 1945 1949 1947 1956 1942 1939 1951 1938 1946 1943 193...
result:
ok 1 cases.
Test #22:
score: 0
Accepted
time: 99ms
memory: 7640kb
input:
2000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
1 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: 94ms
memory: 7628kb
input:
2000 0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
1 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.