QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#505202 | #2833. Hamilton | xiaohuzai | AC ✓ | 123ms | 7760kb | C++14 | 2.8kb | 2024-08-04 21:52:09 | 2024-08-04 21:52:10 |
Judging History
answer
#include<bits/stdc++.h>
#define gt getchar
#define pt putchar
#define fst first
#define scd second
typedef long long ll;
using namespace std;
const int N=2005;
typedef pair<int,int> pii;
inline bool __(char ch){return ch>=48&&ch<=57;}
template<class T> inline void read(T &x){
x=0;bool sgn=0;char ch=gt();
while(!__(ch)&&ch!=EOF) sgn|=(ch=='-'),ch=gt();
while(__(ch)) x=(x<<1)+(x<<3)+(ch&15),ch=gt();
if(sgn) x=-x;
}
template<class T,class ...T1> inline void read(T &x,T1 &...x1){
read(x);
read(x1...);
}
template<class T> inline void print(T x){
static char st[70];short top=0;
if(x<0) pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top) pt(st[top--]);
}
template<class T> inline void printsp(T x){
print(x);
putchar(' ');
}
template<class T> inline void println(T x){
print(x);
putchar('\n');
}
bool a[N][N];
int nxt[N],st,pre[N];
map<int,int>M;
void solve(int n){
M.clear();
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
char ch;cin>>ch;
a[i][j]=ch-'0';
}
}
for(int i=0;i<=n;i++)nxt[i]=0,pre[i]=0;
int nn=1,st=1;
nxt[1]=2,nxt[2]=1;
pre[2]=1;pre[1]=2;
for(int i=3;i<=n;i++){
if(nn==1){
nxt[i]=nxt[st];pre[nxt[st]]=i;
nxt[st]=i;pre[i]=st;
// for(int j=1;j<=n;j++)cout<<nxt[j]<<" "<<a[j][nxt[j]]<<endl;
if(a[i][nxt[i]]!=a[st][i]||a[st][i]!=a[pre[st]][st]||a[i][nxt[i]]!=a[nxt[i]][nxt[nxt[i]]])nn=2;
}
else{
M.clear();
int nw=st,ck=0,ckk=0;
while(nw!=st||ckk==0){
ckk=1;
if(a[pre[nw]][nw]==0&&a[nw][nxt[nw]]==1){
if(a[i][nw]==1){
nxt[pre[nw]]=i,pre[i]=pre[nw];
nxt[i]=nw,pre[nw]=i;
}
else{
pre[nxt[nw]]=i,nxt[i]=nxt[nw];
nxt[nw]=i,pre[i]=nw;
}
ck=1;
break;
}
if(a[pre[nw]][nw]==1&&a[nw][nxt[nw]]==0){
// puts("!");
if(a[i][nw]==1){
pre[nxt[nw]]=i,nxt[i]=nxt[nw];
nxt[nw]=i,pre[i]=nw;
}
else{
nxt[pre[nw]]=i,pre[i]=pre[nw];
nxt[i]=nw,pre[nw]=i;
}
ck=1;
break;
}
assert(nw!=0);
nw=nxt[nw];
}
// for(int j=1;j<=n;j++)cout<<nxt[j]<<" "<<a[j][nxt[j]]<<endl;
nw=st,ckk=0;
while(nw!=st||ckk==0){
// cout<<nw<<endl;
ckk=1;
M[a[nw][nxt[nw]]]=1;
nw=nxt[nw];
}
if((!M[1])||(!M[0]))nn=1;
//assert(ck!=0);
}
}
// for(int i=1;i<=n;i++)cout<<nxt[i]<<" "<<a[i][nxt[i]]<<endl;
for(int i=1;i<=n;i++){
int ck=0,ck1=0,nw=-1;
st=i;
while(st!=i||nw==-1){
nw=0;
if(ck&&a[st][nxt[st]]==0){ck1=-1;break;}
if(a[st][nxt[st]]==1)ck=1;
st=nxt[st];
}
if(ck1==0){
st=i;nw=-1;
while(st!=i||nw==-1){
nw=0;
printsp(st);
st=nxt[st];
}
cout<<endl;
return;
}
}
puts("-1");
//assert(0);
}
int main(){
int n;
while(scanf("%d",&n)!=EOF){
//cin>>n;
solve(n);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
input:
3 001 000 100 4 0000 0000 0000 0000
output:
3 2 1 1 4 3 2
result:
ok 2 cases.
Test #2:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
3 000 000 000 3 010 100 000 3 011 100 100 3 011 101 110
output:
1 3 2 1 3 2 3 2 1 1 3 2
result:
ok 4 cases.
Test #3:
score: 0
Accepted
time: 1ms
memory: 5628kb
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 3 2 1 4 3 2 2 4 1 3 4 3 2 1 2 1 4 3 4 3 2 1 1 4 3 2 2 1 4 3 4 3 2 1 1 3 2 4 1 4 3 2
result:
ok 11 cases.
Test #4:
score: 0
Accepted
time: 0ms
memory: 3780kb
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 3 2 5 4 3 2 1 1 5 4 3 2 4 3 2 1 5 4 3 2 1 5 2 1 4 5 3 5 4 3 2 1 3 2 5 1 4 4 3 2 1 5 1 5 3 2 4 1 5 4 3 2 5 3 2 1 4 4 3 2 1 5 1 5 3 4 2 3 5 4 2 1 2 1 4 5 3 1 5 4 3 2 5 4 3 2 1 5 2 4 1 3 1 3 2 5 4 3 2 5 1 4 2 5 1 4 3 5 4 1 3 2 3 2 1 4 5 5 3 2 1 4 4 1 5 3 2 4 3 2 1 5 5 4...
result:
ok 34 cases.
Test #5:
score: 0
Accepted
time: 1ms
memory: 3716kb
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 3 2 1 6 5 4 3 2 1 6 3 2 5 4 3 2 1 5 6 4 3 2 1 5 6 4 2 1 4 5 6 3 6 1 5 3 2 4 3 2 1 5 6 4 6 5 4 3 2 1 2 1 6 5 4 3 2 1 6 5 4 3 4 1 6 5 3 2 5 1 6 4 3 2 6 5 4 3 2 1 1 6 5 4 3 2 1 6 5 4 3 2 1 5 4 3 2 6 5 4 3 2 1 6 1 5 6 3 2 4 6 5 4 3 2 1 6 5 4 3 2 1 6 4 3 2 1 5 6 4 3 2 1 5 1...
result:
ok 156 cases.
Test #6:
score: 0
Accepted
time: 1ms
memory: 3768kb
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:
1 5 6 4 7 3 2 2 6 1 5 4 7 3 2 1 3 6 5 7 4 7 5 6 4 3 2 1 2 1 4 7 5 6 3 2 1 5 6 7 4 3 2 1 6 7 5 4 3 1 7 6 3 4 5 2 7 6 5 2 4 1 3 6 3 2 5 1 4 7 7 6 4 3 2 5 1 2 4 1 7 3 6 5 2 1 4 3 5 6 7 7 6 5 2 4 1 3 5 7 6 2 1 3 4 7 6 5 4 3 2 1 1 7 4 3 5 6 2 7 5 3 4 2 1 6 7 1 6 5 3 2 4 4 7 6 5 3 2 1 ...
result:
ok 286 cases.
Test #7:
score: 0
Accepted
time: 1ms
memory: 3636kb
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 3 5 2 4 9 7 6 3 2 5 4 1 8 2 1 4 3 2 1 4 3 6 7 8 5 6 3 4 5 2 1 9 8 7 1 3 2 4 1 6 5 3 2 4 6 3 5 2 4 1 6 5 3 2 1 4 7 4 6 1 7 5 3 2 10 8 5 4 3 2 1 7 6 9 10 5 3 2 4 1 6 7 8 9 1 5 4 6 3 2 8 7 6 3 5 2 4 1 9 8 5 3 2 4 1 7 6 2 1 3 1 3 2 6 5 4 3 2 1 4 1 5 6 7 3 2 1 3 2 2 1 3 3 2 1 4 5 ...
result:
ok 322 cases.
Test #8:
score: 0
Accepted
time: 1ms
memory: 3776kb
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:
2 1 5 7 10 9 8 6 4 3 4 3 2 1 8 9 7 10 6 5 5 1 4 3 8 7 10 9 6 2 4 10 9 8 6 7 3 2 5 1 2 1 4 5 9 10 8 7 6 3 10 8 9 4 3 2 1 5 6 7 1 10 9 8 7 6 5 4 3 2 3 4 2 1 6 7 10 9 8 5 2 1 3 4 6 7 8 9 10 5 1 10 7 8 6 9 4 5 3 2 6 1 5 4 3 10 8 9 7 2 7 10 9 8 5 3 2 4 1 6 3 2 1 6 7 5 8 4 9 10 2 4 1 5 6 7 9 ...
result:
ok 200 cases.
Test #9:
score: 0
Accepted
time: 1ms
memory: 3708kb
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 5 4 3 2 1 7 8 10 9 6 7 5 3 4 2 1 4 1 10 3 9 6 8 7 5 2 6 1 5 4 7 8 10 9 3 2 6 1 5 7 3 8 10 9 2 4 8 10 9 6 5 4 3 2 1 7 10 8 7 6 4 5 3 2 1 9 7 6 3 2 5 4 1 10 9 8 8 10 9 3 2 1 4 5 6 7 6 4 3 2 5 1 8 10 9 7 2 4 6 1 5 3 7 8 9 10 1 10 9 8 7 6 5 4 3 2 3 2 1 4 5 6 7 8 9 10 4 3 2 1 6 7 10...
result:
ok 200 cases.
Test #10:
score: 0
Accepted
time: 3ms
memory: 3676kb
input:
20 00011111000111100010 00100111111000000010 01011011101000100111 10100010000100000010 10100100000010101101 11001001010010000111 11110000010000111001 11100100111000010101 01100001011101100010 01000111100111011001 01100001100111111111 10010000111001010000 10001100011001001000 10000000111110111010 101...
output:
1 20 19 18 15 16 17 13 14 12 11 8 9 10 7 4 3 2 6 5 10 9 8 4 5 6 3 7 2 1 12 11 15 18 19 17 16 14 13 22 12 10 11 6 3 2 1 5 4 8 9 13 16 17 18 19 14 20 15 21 7 3 2 1 5 6 13 11 12 10 9 8 7 4 3 2 1 5 6 7 4 10 11 14 13 15 16 24 25 23 27 30 28 29 26 22 18 21 20 19 17 12 9 8 21 20 13 10 11 9 12 6 7 8 3 ...
result:
ok 72 cases.
Test #11:
score: 0
Accepted
time: 5ms
memory: 3760kb
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 3 2 1 4 5 8 21 25 26 27 30 35 49 50 57 4 1 3 7 8 9 10 11 14 15 13 16 26 27 29 30 31 32 33 28 34 35 25 36 38 42 43 44 41 45 39 46 48 49 47 50 54 56 57 62 63 58 61 60 59 55...
result:
ok 29 cases.
Test #12:
score: 0
Accepted
time: 10ms
memory: 4056kb
input:
160 0010110100011110110110110001100110111000000100001100110101001011100101011100011100111011011011010011010110101100000011111010110111001011001100010000101111001101 000011011110000111010100011011010001001101001100111010101101001011001101001001000001011010001101100111011110110101111010101100000101001...
output:
11 1 10 5 12 14 15 13 16 7 17 20 21 19 22 24 25 26 27 32 33 36 40 39 41 46 48 49 52 53 51 62 63 61 64 56 65 66 68 69 71 72 74 75 76 77 78 80 79 88 91 113 116 154 160 155 159 158 157 156 153 115 152 117 151 119 150 120 149 118 148 137 147 138 146 143 145 144 139 142 140 141 122 136 131 135 134 132 13...
result:
ok 14 cases.
Test #13:
score: 0
Accepted
time: 21ms
memory: 6192kb
input:
438 01000100111101110010100101010001000101100011101011001001011110011100000110001001100101100101110011110111001101001101100111110010011001000110100110101001001101110001110011101010100010110100001011110011001000000001111111011001001010011101110010110111011111100011111101101001101010101010110000000111...
output:
438 435 434 433 432 430 431 429 427 425 424 411 423 410 422 412 421 420 419 413 418 416 417 415 414 409 408 407 379 378 367 366 342 343 339 334 336 335 333 331 328 327 285 319 314 318 317 316 315 302 313 312 307 311 310 309 308 306 305 304 303 301 299 300 278 284 279 283 280 282 281 274 273 272 268 ...
result:
ok 7 cases.
Test #14:
score: 0
Accepted
time: 68ms
memory: 6332kb
input:
1227 0100010000101001111110111010100100001100101111001011101010010000100111110110000001101101000101010011000101100110010011010100010011111000101101011001010111010010101001100100011000100000101011011011110101010011011110111101110010100010101111010101011001100001000110011101101010010011110010011011100...
output:
4 1 7 8 9 6 10 12 13 19 20 23 24 22 27 29 30 32 35 49 50 51 52 53 54 55 56 57 36 58 61 60 62 59 63 48 64 66 65 67 47 77 78 79 90 91 92 89 96 99 98 102 101 123 127 129 130 131 132 128 133 135 136 134 137 139 140 141 142 143 156 157 158 159 162 163 166 167 168 170 175 180 189 192 193 191 194 196 195 1...
result:
ok 2 cases.
Test #15:
score: 0
Accepted
time: 63ms
memory: 5992kb
input:
1078 0111011100111011000000110100010011001100100101011100111000110001110111110010111010110111010110001010100111101001110111010010000001000100110000000010000010111010101000000110101011011011000001100000011111010001010001101111011110111110000110111111111111101100110100011001110110111011111001110010110...
output:
12 28 1 27 26 25 23 24 22 15 21 18 20 19 17 16 14 13 30 31 35 36 37 34 38 39 40 42 43 44 45 47 48 46 51 54 53 56 57 65 66 67 68 70 71 69 72 77 76 78 79 75 83 82 84 86 88 92 93 94 96 97 98 95 99 91 100 101 108 109 110 111 112 113 121 122 125 128 132 133 135 136 149 153 152 154 155 157 156 159 160 167...
result:
ok 2 cases.
Test #16:
score: 0
Accepted
time: 73ms
memory: 7516kb
input:
1310 0110101010101111001001001110010101000100000000011001001110111010011000110110010000001110111100110100110110110000011001000101100100000011011111011100010001101111001100100000011100111111101101001011000101000011100101111011100101011111000100101110011110001101110110100111101101011000000000101000101...
output:
1310 1305 1301 1287 1300 1299 1296 1298 1297 1282 1285 1284 1283 1277 1276 1275 1272 1271 1269 1268 1267 1263 1264 1260 1259 1258 1256 1255 1253 1248 1252 1251 1250 1249 1245 1247 1246 1244 1241 1243 1242 1239 1240 1235 1234 1233 1228 1222 1226 1223 1225 1224 1220 1217 1214 1215 1212 1191 1197 1195 ...
result:
ok 2 cases.
Test #17:
score: 0
Accepted
time: 82ms
memory: 6784kb
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: 120ms
memory: 7756kb
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: 120ms
memory: 7752kb
input:
2000 0100001100010101000111011110110000001010100001111010011110111010011101000001100111011101101100000100100011001100011101011110101011101000010000000001010110001100011111100011010110101010001100011100011100000111011011100010110010100001111101011001010111111101011100111011110001101000111100110101000...
output:
11 1 10 7 9 6 5 3 14 15 13 19 20 16 21 32 33 38 39 37 40 42 46 47 50 49 77 78 76 79 80 73 84 85 83 86 97 98 117 118 120 119 121 133 132 134 149 151 150 152 148 153 155 154 156 157 158 160 161 163 162 164 165 166 168 169 170 167 171 185 186 187 189 193 194 190 198 199 200 201 202 197 212 213 214 211 ...
result:
ok 1 cases.
Test #20:
score: 0
Accepted
time: 123ms
memory: 7620kb
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: 115ms
memory: 7756kb
input:
2000 0110000110000000010000010011101111110001110101010000000001101110101010101001111001010100100101001100010100101000110001000101000101010011011000000100011110100001000010000111100110111010110001000100011100100011111001011011111011111001101101111011111011111010011100001111010001011101110000000001011...
output:
9 15 1 14 8 16 18 19 20 21 23 24 25 30 31 32 33 29 34 41 44 45 53 54 57 64 65 72 73 74 75 82 85 86 87 84 89 90 88 91 83 92 99 98 100 101 102 97 103 95 104 105 109 110 119 120 121 122 118 125 126 133 134 127 136 137 138 143 146 147 148 145 157 158 166 167 168 165 169 162 173 174 175 177 178 176 179 1...
result:
ok 1 cases.
Test #22:
score: 0
Accepted
time: 117ms
memory: 7760kb
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: 113ms
memory: 7752kb
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.