QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#190628 | #2833. Hamilton | qzez# | AC ✓ | 13ms | 7556kb | C++14 | 1.2kb | 2023-09-29 08:37:40 | 2023-09-29 08:37:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
if(x.empty())return out<<"[]";
out<<'['<<x[0];
for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
cerr<<x<<' ',debug(y...);
}
const int N=2e3+10;
int n,m,ans[N];
char a[N][N];
int find(){
for(int i=1;i<=m;i++){
int x=ans[i>1?i-1:m],y=ans[i],z=ans[i%m+1];
if(a[x][y]=='1'&&a[y][z]=='0')return i;
}
return -1;
}
void insert(int x,int y){
for(int i=m;i>=x;i--)ans[i+1]=ans[i];
ans[x]=y,m++;
}
void get(){
for(int i=1;i<=n;i++)scanf("%s",a[i]+1);
m=2,ans[1]=1,ans[2]=2;
for(int i=3;i<=n;i++){
int t=find();
if(!~t)ans[++m]=i;
else{
int x=ans[t>1?t-1:m],y=ans[t],z=ans[t%m+1];
if(a[x][i]=='0'&&a[i][y]=='1')insert(t%m+1,i);
else insert(t,i);
}
}
int t=find();
if(!~t)t=1;
for(int i=1;i<=n;i++,t=t%m+1)printf("%d%c",ans[t],"\n "[i<n]);
}
int main(){
for(;~scanf("%d",&n);)get();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3772kb
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: 0
Accepted
time: 1ms
memory: 3604kb
input:
3 000 000 000 3 010 100 000 3 011 100 100 3 011 101 110
output:
1 2 3 2 3 1 2 3 1 1 2 3
result:
ok 4 cases.
Test #3:
score: 0
Accepted
time: 1ms
memory: 5632kb
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 2 3 4 1 2 3 4 2 4 3 1 4 2 3 1 4 1 2 3 3 4 1 2 1 2 3 4 3 1 2 4 2 4 3 1 1 4 2 3 4 1 2 3
result:
ok 11 cases.
Test #4:
score: 0
Accepted
time: 1ms
memory: 3560kb
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 2 3 4 5 1 2 3 4 5 5 1 2 3 4 5 1 2 3 4 1 2 3 4 5 5 4 1 2 3 5 3 1 4 2 1 2 3 4 5 3 4 1 2 5 1 2 3 4 5 1 2 3 4 5 2 3 1 4 5 4 3 1 2 5 2 3 1 4 5 5 4 2 3 1 5 4 1 2 3 4 5 1 2 3 3 4 1 2 5 5 2 3 4 1 1 2 3 4 5 1 2 3 4 5 1 2 4 3 5 4 5 1 2 3 5 4 1 2 3 2 3 1 4 5 3 1 2 4 5 5 1 2 3 4 5 4 1 2 3 5 2 3 1 4 5 4 1 2 3 ...
result:
ok 34 cases.
Test #5:
score: 0
Accepted
time: 1ms
memory: 3624kb
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 2 3 4 5 6 1 2 3 4 5 6 1 6 2 5 4 3 4 6 5 1 2 3 6 5 1 2 3 4 6 5 4 1 2 3 6 5 1 2 3 4 6 5 1 2 3 4 6 5 4 1 2 3 6 4 1 2 3 5 6 4 1 2 3 5 3 1 2 4 5 6 5 4 1 2 3 6 5 6 1 2 3 4 1 2 3 4 5 6 1 2 3 4 5 6 3 1 2 4 5 6 6 4 5 1 2 3 1 2 3 4 5 6 5 6 3 4 1 2 3 6 4 5 1 2 3 4 1 2 5 6 5 4 1 2 3 6 6 3 1 2 4 5 3 4 1 2 5 6 ...
result:
ok 156 cases.
Test #6:
score: 0
Accepted
time: 1ms
memory: 3492kb
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:
6 5 1 2 3 7 4 5 7 6 1 2 4 3 7 5 6 3 1 2 4 5 7 1 2 3 4 6 7 4 1 2 3 6 5 6 7 1 2 4 5 3 6 1 2 3 4 5 7 1 2 5 4 3 6 7 7 6 4 5 1 2 3 6 5 2 3 4 1 7 7 6 1 2 3 4 5 7 2 4 3 1 5 6 7 6 5 3 4 1 2 1 7 6 5 4 2 3 7 2 3 1 5 6 4 4 7 1 2 5 3 6 1 5 4 2 3 6 7 7 5 6 1 2 4 3 7 3 6 4 1 5 2 1 5 4 2 3 6 7 7 6 5 1 2 3 4 7 1 2 ...
result:
ok 286 cases.
Test #7:
score: 0
Accepted
time: 1ms
memory: 3648kb
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:
3 5 4 1 2 9 7 4 6 5 1 2 3 8 3 1 2 4 4 1 2 8 6 7 5 3 9 7 1 2 5 4 3 6 8 1 4 2 3 6 2 3 1 5 4 2 6 3 5 4 1 7 2 5 3 4 1 6 6 1 4 2 3 5 7 6 5 1 2 4 7 8 3 9 10 7 4 6 5 1 2 3 8 9 10 2 6 5 3 4 1 7 8 4 6 5 1 2 3 9 7 8 5 6 1 2 3 4 1 2 3 1 2 3 6 5 4 2 3 1 7 6 5 4 3 1 2 2 3 1 1 2 3 2 3 1 4 5 1 6 2 5 3 4 8 6 7 5 1 ...
result:
ok 322 cases.
Test #8:
score: 0
Accepted
time: 1ms
memory: 3612kb
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:
9 1 2 3 5 4 7 6 8 10 10 7 9 8 1 2 3 4 5 6 9 8 6 3 4 1 2 7 5 10 10 9 5 8 6 7 1 2 3 4 10 6 5 4 1 2 3 7 9 8 10 8 9 5 4 2 3 1 6 7 9 8 6 7 1 5 4 2 3 10 10 8 7 6 1 2 4 3 5 9 10 1 2 8 6 7 5 4 3 9 4 3 1 5 2 8 7 9 6 10 1 5 4 2 3 7 6 9 8 10 10 4 2 3 1 6 8 7 9 5 10 9 4 8 5 7 6 1 2 3 10 7 6 5 4 1 2 8 9 3 10 8 6...
result:
ok 200 cases.
Test #9:
score: 0
Accepted
time: 1ms
memory: 3556kb
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 9 8 6 1 2 3 5 4 7 8 10 9 6 3 1 4 5 2 7 10 9 7 6 4 3 1 2 5 8 6 9 7 8 5 3 4 1 2 10 7 3 6 5 1 4 8 2 9 10 10 6 3 1 2 4 5 8 9 7 10 5 9 7 8 4 6 1 2 3 8 5 6 1 2 4 3 7 9 10 9 10 8 3 4 1 2 5 6 7 10 8 7 5 1 4 2 3 6 9 6 4 1 2 3 5 7 8 9 10 10 9 8 7 6 5 4 1 2 3 9 2 3 1 4 5 6 7 8 10 8 10 9 4 7 6 1 2 3 5 10 9 8...
result:
ok 200 cases.
Test #10:
score: 0
Accepted
time: 1ms
memory: 3652kb
input:
20 00011111000111100010 00100111111000000010 01011011101000100111 10100010000100000010 10100100000010101101 11001001010010000111 11110000010000111001 11100100111000010101 01100001011101100010 01000111100111011001 01100001100111111111 10010000111001010000 10001100011001001000 10000000111110111010 101...
output:
20 19 18 15 6 7 5 2 3 4 1 8 10 9 12 11 13 14 16 17 19 12 6 11 9 10 5 4 1 2 7 3 14 15 8 16 17 18 13 22 19 16 14 10 13 7 12 11 6 5 3 1 2 4 8 9 15 17 18 21 20 13 6 5 1 2 3 4 8 9 10 7 11 12 30 29 25 23 20 18 13 16 10 15 14 11 8 7 1 2 3 5 4 6 9 12 17 19 21 22 26 27 24 28 21 18 16 15 12 14 13 4 7 6 5 3 1 ...
result:
ok 72 cases.
Test #11:
score: 0
Accepted
time: 2ms
memory: 5944kb
input:
59 01110100011001000100111000110110010001011111001011011101100 10001011111001111100111111100010111011100101001100001000101 10000011101010011100111011000001101110001100001110110101001 10001100100110101001000000101101101110001110111001110001101 010101010101101111110011111000100101111111101001111100111...
output:
59 58 54 53 51 52 48 46 47 42 45 44 43 41 35 40 38 39 36 37 31 34 33 32 27 29 28 26 23 24 21 22 20 7 19 18 11 17 12 16 13 15 14 9 10 6 2 3 1 4 5 8 25 49 50 55 30 56 57 62 63 61 59 58 57 56 54 51 50 48 49 37 47 46 44 43 39 38 22 36 25 35 34 28 33 32 31 30 29 27 26 21 16 14 15 13 10 4 9 8 6 7 5 3 1 11...
result:
ok 29 cases.
Test #12:
score: 0
Accepted
time: 0ms
memory: 5956kb
input:
160 0010110100011110110110110001100110111000000100001100110101001011100101011100011100111011011011010011010110101100000011111010110111001011001100010000101111001101 000011011110000111010100011011010001001101001100111010101101001011001101001001000001011010001101100111011110110101111010101100000101001...
output:
156 152 137 150 148 149 147 145 146 144 140 143 142 141 139 138 136 135 124 132 131 125 123 118 120 119 117 115 116 113 112 110 108 106 105 90 100 99 96 98 97 92 95 94 93 91 88 89 85 87 86 83 81 79 80 78 77 76 75 74 72 71 69 66 64 61 63 62 56 54 51 53 52 49 50 46 43 42 40 41 37 36 33 32 27 26 25 22 ...
result:
ok 14 cases.
Test #13:
score: 0
Accepted
time: 0ms
memory: 6260kb
input:
438 01000100111101110010100101010001000101100011101011001001011110011100000110001001100101100101110011110111001101001101100111110010011001000110100110101001001101110001110011101010100010110100001011110011001000000001111111011001001010011101110010110111011111100011111101101001101010101010110000000111...
output:
416 435 434 424 433 423 432 430 431 429 428 425 427 426 422 421 420 419 413 418 417 415 414 406 409 408 407 403 399 391 389 385 374 372 371 366 367 365 364 359 356 349 348 343 338 334 336 335 332 333 331 328 319 317 318 315 316 313 312 307 311 310 309 308 306 305 303 304 302 298 301 300 299 297 289 ...
result:
ok 7 cases.
Test #14:
score: 0
Accepted
time: 3ms
memory: 6864kb
input:
1227 0100010000101001111110111010100100001100101111001011101010010000100111110110000001101101000101010011000101100110010011010100010011111000101101011001010111010010101001100100011000100000101011011011110101010011011110111101110010100010101111010101011001100001000110011101101010010011110010011011100...
output:
1225 1227 1226 1218 1216 1217 1214 1215 1213 1212 1201 1210 1203 1209 1208 1207 1206 1205 1204 1202 1199 1200 1198 1197 1196 1195 1194 1189 1193 1192 1190 1182 1188 1181 1187 1183 1186 1184 1185 1177 1164 1172 1171 1167 1165 1166 1161 1163 1162 1155 1160 1156 1159 1157 1158 1152 1150 1149 1147 1146 ...
result:
ok 2 cases.
Test #15:
score: 0
Accepted
time: 5ms
memory: 6652kb
input:
1078 0111011100111011000000110100010011001100100101011100111000110001110111110010111010110111010110001010100111101001110111010010000001000100110000000010000010111010101000000110101011011011000001100000011111010001010001101111011110111110000110111111111111101100110100011001110110111011111001110010110...
output:
1074 1075 1068 1069 1061 1064 1063 1059 1060 1056 1057 1054 1055 1050 1049 1047 1045 1037 1044 1036 1043 1042 1040 1041 1038 1039 1028 1025 1027 1026 1019 1023 1022 1021 1020 1012 1006 1011 1010 1009 1007 1008 1005 998 1002 1001 1000 996 994 990 992 991 989 987 983 984 982 981 980 979 978 969 962 96...
result:
ok 2 cases.
Test #16:
score: 0
Accepted
time: 7ms
memory: 6584kb
input:
1310 0110101010101111001001001110010101000100000000011001001110111010011000110110010000001110111100110100110110110000011001000101100100000011011111011100010001101111001100100000011100111111101101001011000101000011100101111011100101011111000100101110011110001101110110100111101101011000000000101000101...
output:
1310 1307 1302 1306 1305 1296 1298 1297 1287 1282 1285 1284 1283 1281 1278 1277 1276 1275 1272 1271 1265 1269 1267 1268 1262 1264 1263 1261 1260 1259 1256 1254 1253 1252 1251 1250 1248 1245 1247 1246 1244 1241 1243 1242 1240 1226 1224 1225 1223 1219 1211 1218 1217 1212 1216 1214 1215 1213 1208 1205 ...
result:
ok 2 cases.
Test #17:
score: 0
Accepted
time: 3ms
memory: 6856kb
input:
1542 0000100001001001100011001101100001110111010111001110111110011011001000110010001111000000100011101001000100000001111001110100110101101111000011100010000100000111010001010110101110000001000001110100101111100001110010111000111001010111011100100100111011010101001100100101110110011000001011001000011...
output:
1542 1495 1540 1539 1538 1496 1537 1536 1523 1535 1534 1533 1532 1531 1530 1524 1529 1528 1527 1525 1526 1498 1522 1501 1521 1520 1511 1519 1517 1518 1510 1516 1514 1515 1513 1512 1509 1508 1504 1507 1505 1506 1503 1502 1499 1500 1497 1489 1492 1491 1490 1487 1438 1483 1482 1481 1451 1480 1440 1479 ...
result:
ok 2 cases.
Test #18:
score: 0
Accepted
time: 9ms
memory: 7524kb
input:
2000 0101010000001001011001110100110110001010001110110101101100010010011100000111001100000000110111011111100001110001111011101101110010100100001001110010001111011110011011010000100001011100000000110011000110010100101010110100001010101001111101011001110011010001100110000110101110000001000101001101010...
output:
1997 1996 1993 1992 1990 1972 1987 1986 1985 1974 1984 1981 1983 1982 1973 1980 1979 1977 1978 1975 1976 1971 1970 1966 1969 1968 1967 1962 1963 1961 1958 1957 1952 1956 1955 1954 1953 1951 1950 1949 1948 1941 1947 1946 1943 1945 1944 1940 1938 1936 1937 1934 1933 1931 1927 1925 1922 1923 1921 1915 ...
result:
ok 1 cases.
Test #19:
score: 0
Accepted
time: 13ms
memory: 7544kb
input:
2000 0100001100010101000111011110110000001010100001111010011110111010011101000001100111011101101100000100100011001100011101011110101011101000010000000001010110001100011111100011010110101010001100011100011100000111011011100010110010100001111101011001010111111101011100111011110001101000111100110101000...
output:
1996 2000 1999 1997 1998 1993 1989 1992 1991 1988 1978 1962 1977 1969 1976 1972 1975 1973 1974 1963 1971 1970 1968 1967 1965 1966 1964 1949 1961 1952 1960 1954 1959 1957 1958 1956 1955 1953 1946 1947 1944 1943 1937 1922 1936 1923 1935 1933 1934 1924 1932 1931 1929 1930 1928 1925 1927 1926 1914 1913 ...
result:
ok 1 cases.
Test #20:
score: 0
Accepted
time: 7ms
memory: 7480kb
input:
2000 0110101010100011101110010101000111001011110000101111001110111111100111000101010001110111000110110001010000010101101001011001111111011111111111011111000011100001111110000101100100000110100100100110110010000101101101100100001101100010011100000011110000100100011110111001101001101100110111011101011...
output:
2000 1999 1997 1998 1991 1996 1994 1995 1989 1990 1988 1984 1983 1982 1981 1980 1979 1978 1975 1977 1976 1963 1964 1961 1960 1957 1950 1956 1955 1952 1951 1944 1945 1938 1939 1937 1929 1931 1930 1927 1923 1922 1919 1920 1918 1916 1913 1912 1905 1902 1891 1893 1892 1890 1887 1889 1888 1886 1884 1883 ...
result:
ok 1 cases.
Test #21:
score: 0
Accepted
time: 0ms
memory: 7464kb
input:
2000 0110000110000000010000010011101111110001110101010000000001101110101010101001111001010100100101001100010100101000110001000101000101010011011000000100011110100001000010000111100110111010110001000100011100100011111001011011111011111001101101111011111011111010011100001111010001011101110000000001011...
output:
1997 2000 1999 1998 1995 1996 1994 1983 1990 1985 1989 1987 1988 1986 1984 1976 1982 1977 1981 1980 1978 1979 1974 1972 1973 1969 1967 1965 1953 1964 1957 1963 1954 1962 1961 1960 1958 1959 1956 1955 1949 1951 1950 1947 1946 1945 1941 1944 1943 1942 1937 1936 1935 1929 1920 1928 1927 1921 1917 1916 ...
result:
ok 1 cases.
Test #22:
score: 0
Accepted
time: 13ms
memory: 7536kb
input:
2000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok 1 cases.
Test #23:
score: 0
Accepted
time: 9ms
memory: 7556kb
input:
2000 0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok 1 cases.