QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#382871 | #2833. Hamilton | waretle | AC ✓ | 14ms | 7760kb | C++14 | 1.5kb | 2024-04-08 19:54:59 | 2024-04-08 19:54:59 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int n,p[2005],cur;
char mp[2005][2005];
int c(int i){return i==cur?mp[p[cur]][p[1]]:mp[p[i]][p[i+1]];}
int nxt(int i){return i==cur?1:i+1;}
void ins(int x,int y)
{
for(int i=cur+1;i>x;--i)p[i]=p[i-1];
p[x]=y;
}
int main()
{
while(~scanf("%d",&n))
{
for(int i=1;i<=n;++i)scanf("%s",mp[i]+1);
for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)mp[i][j]-='0';
p[1]=1,p[2]=2;
for(int i=3;i<=n;++i)
{
cur=i-1;
int pos=0;
for(int j=1;j+1<i;++j)
if(c(j)!=c(nxt(j)))
assert(!pos),pos=j;
// cerr<<pos<<'\n';
// cerr<<c(1)<<' '<<c(2)<<'\n';
if(!pos)
{
p[i]=i,cur=i;
for(int j=1;j<i;++j)
if(c(j)!=c(nxt(j)))
{
rotate(p+1,p+j+1,p+i+1);
break;
}
}
else
{
if(mp[p[pos]][i]==mp[p[nxt(pos)]][i])
ins(pos+1,i);
else if(mp[p[nxt(pos)]][i]==mp[p[nxt(nxt(pos))]][i])
ins(pos+2,i);
else if(mp[p[nxt(pos)]][i]==c(pos))
ins(pos+2,i);
else ins(pos+1,i);
}
}
for(int i=1;i<=n;++i)printf("%d ",p[i]);
puts("");
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3968kb
input:
3 001 000 100 4 0000 0000 0000 0000
output:
3 1 2 1 2 3 4
result:
ok 2 cases.
Test #2:
score: 0
Accepted
time: 0ms
memory: 3880kb
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: 0ms
memory: 3776kb
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 3 4 1 2 2 4 3 1 2 3 4 1 3 4 1 2 1 2 3 4 2 4 3 1 3 4 1 2 2 3 1 4 3 4 1 2
result:
ok 11 cases.
Test #4:
score: 0
Accepted
time: 0ms
memory: 3792kb
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 5 1 2 3 4 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 2 3 5 1 4 2 3 5 4 1 3 4 5 1 2 3 4 5 1 2 2 3 4 5 1 1 2 3 4 5 2 3 4 5 1 2 3 4 5 1 1 5 2 4 3 2 3 5 4 1 2 3 4 5 1 4 5 1 2 3 3 4 1 5 2 3 4 1 5 2 2 3 4 5 1 3 4 5 1 2 2 4 3 5 1 2 3 4 5 1 3 1 5 4 2 2 3 5 4 1 3 4 5 1 2 4 5 1 2 3 5 3...
result:
ok 34 cases.
Test #5:
score: 0
Accepted
time: 0ms
memory: 3960kb
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 2 3 4 5 6 1 3 4 6 1 5 2 3 4 1 6 5 2 2 3 1 6 5 4 3 4 1 6 5 2 3 4 1 6 5 2 4 6 5 1 2 3 2 3 5 1 6 4 2 3 5 4 6 1 3 1 6 5 4 2 4 5 6 1 2 3 5 6 1 2 3 4 1 2 3 4 5 6 1 2 3 4 5 6 2 4 5 6 3 1 4 5 6 1 2 3 2 3 4 5 6 1 3 4 5 6 1 2 4 6 5 1 2 3 3 4 5 6 1 2 4 1 6 5 2 3 6...
result:
ok 156 cases.
Test #6:
score: 0
Accepted
time: 1ms
memory: 3836kb
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:
3 7 4 6 5 1 2 2 7 6 5 3 4 1 2 4 5 7 6 3 1 7 4 6 5 1 2 3 2 3 1 6 5 7 4 2 4 5 3 6 7 1 2 3 4 5 7 6 1 2 7 3 6 5 4 1 7 3 6 4 5 1 2 3 4 1 7 5 6 2 2 3 4 5 7 1 6 2 7 3 6 4 5 1 2 6 7 3 5 4 1 3 1 6 4 7 5 2 2 6 7 3 5 4 1 3 4 5 7 1 6 2 1 7 2 6 5 3 4 5 6 2 7 4 3 1 5 7 6 2 3 4 1 2 3 5 7 6 4 1 ...
result:
ok 286 cases.
Test #7:
score: 0
Accepted
time: 1ms
memory: 3864kb
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 1 4 5 2 2 3 9 4 8 7 6 5 1 2 4 3 1 2 8 6 7 5 3 4 1 6 9 8 2 7 5 3 4 1 2 3 1 4 3 1 5 4 6 2 3 1 4 5 2 6 3 5 6 7 4 1 2 4 7 5 6 2 3 1 10 5 9 6 8 7 3 4 1 2 3 4 1 6 7 8 9 10 5 2 3 6 4 5 1 2 3 7 8 4 6 5 1 2 3 4 7 9 8 5 6 1 2 2 3 1 1 2 3 2 3 5 4 6 1 3 4 5 6 1 7 2 2 3 1 2 3 1 2 4 5 3 1 ...
result:
ok 322 cases.
Test #8:
score: 0
Accepted
time: 1ms
memory: 3864kb
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:
10 2 9 7 8 3 6 5 1 4 4 5 6 7 10 9 8 1 2 3 3 4 5 1 7 8 6 10 9 2 4 5 10 9 8 6 7 1 2 3 2 3 8 9 7 10 5 6 4 1 2 3 9 10 4 8 7 6 5 1 2 4 6 7 8 9 10 5 3 1 1 5 8 9 10 6 7 2 4 3 2 6 3 10 9 8 7 5 4 1 2 9 10 6 8 7 3 5 4 1 2 4 5 3 6 1 10 8 9 7 3 1 6 9 10 8 5 7 4 2 3 1 5 9 10 8 6 7 4 2 3 1 4 5 6 9 10...
result:
ok 200 cases.
Test #9:
score: 0
Accepted
time: 1ms
memory: 3800kb
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:
3 7 6 8 4 10 9 5 1 2 10 8 9 5 7 6 2 4 3 1 3 4 10 9 1 8 7 5 6 2 3 5 6 4 7 10 8 9 1 2 4 5 6 2 7 8 9 3 10 1 5 3 6 8 4 9 10 7 1 2 6 7 8 9 10 3 5 4 1 2 2 3 1 10 9 8 7 5 6 4 3 7 5 8 10 9 6 4 1 2 2 4 3 5 1 8 10 9 7 6 3 1 4 6 10 9 8 7 5 2 3 4 6 7 8 10 5 9 1 2 2 3 10 8 9 7 6 5 4 1 2 5 9 10 8 7 6...
result:
ok 200 cases.
Test #10:
score: 0
Accepted
time: 1ms
memory: 3848kb
input:
20 00011111000111100010 00100111111000000010 01011011101000100111 10100010000100000010 10100100000010101101 11001001010010000111 11110000010000111001 11100100111000010101 01100001011101100010 01000111100111011001 01100001100111111111 10010000111001010000 10001100011001001000 10000000111110111010 101...
output:
2 3 4 1 8 10 12 11 13 14 16 17 20 18 19 15 6 9 7 5 12 13 2 16 15 19 17 18 14 3 1 7 6 8 5 9 4 11 10 2 3 11 12 6 13 10 21 22 20 14 19 18 17 15 16 7 9 8 4 5 1 3 4 8 10 9 11 13 5 12 7 6 1 2 3 5 4 6 9 12 17 19 20 21 22 26 27 24 28 30 25 29 23 13 18 16 10 15 14 11 8 7 1 2 2 3 1 5 6 7 8 9 4 10 22 21 1...
result:
ok 72 cases.
Test #11:
score: 0
Accepted
time: 1ms
memory: 4032kb
input:
59 01110100011001000100111000110110010001011111001011011101100 10001011111001111100111111100010111011100101001100001000101 10000011101010011100111011000001101110001100001110110101001 10001100100110101001000000101101101110001110111001110001101 010101010101101111110011111000100101111111101001111100111...
output:
2 4 3 5 7 6 8 9 14 15 13 16 17 12 18 19 20 22 21 24 28 32 29 36 39 40 43 44 46 47 51 53 55 56 58 57 59 54 49 52 50 48 45 41 42 38 34 37 35 33 31 30 23 27 25 26 11 1 10 2 3 7 8 9 11 15 25 16 27 26 28 29 31 30 33 34 35 36 38 43 44 46 49 47 50 51 48 54 58 63 59 62 61 60 57 55 56 52 53 45 42 41 39 40 3...
result:
ok 29 cases.
Test #12:
score: 0
Accepted
time: 0ms
memory: 6096kb
input:
160 0010110100011110110110110001100110111000000100001100110101001011100101011100011100111011011011010011010110101100000011111010110111001011001100010000101111001101 000011011110000111010100011011010001001101001100111010101101001011001101001001000001011010001101100111011110110101111010101100000101001...
output:
2 6 7 18 22 20 23 21 29 28 44 47 48 45 55 65 81 82 83 92 96 97 95 100 101 102 103 105 108 109 110 114 122 121 134 147 148 137 151 156 157 154 159 160 158 155 152 153 149 150 146 145 140 144 143 142 141 139 138 135 136 128 133 129 132 130 131 127 124 126 125 123 118 120 119 117 115 116 111 113 107 11...
result:
ok 14 cases.
Test #13:
score: 0
Accepted
time: 0ms
memory: 4628kb
input:
438 01000100111101110010100101010001000101100011101011001001011110011100000110001001100101100101110011110111001101001101100111110010011001000110100110101001001101110001110011101010100010110100001011110011001000000001111111011001001010011101110010110111011111100011111101101001101010101010110000000111...
output:
2 3 1 5 7 6 10 8 18 19 21 22 20 37 41 42 35 44 43 45 47 77 78 48 91 92 94 95 96 97 93 99 115 116 120 121 117 125 126 127 128 134 139 138 142 143 146 147 144 155 148 156 154 162 164 166 165 184 185 183 187 188 189 186 190 182 199 200 201 198 202 203 194 204 205 197 211 225 214 226 230 231 227 234 235...
result:
ok 7 cases.
Test #14:
score: 0
Accepted
time: 7ms
memory: 6376kb
input:
1227 0100010000101001111110111010100100001100101111001011101010010000100111110110000001101101000101010011000101100110010011010100010011111000101101011001010111010010101001100100011000100000101011011011110101010011011110111101110010100010101111010101011001100001000110011101101010010011110010011011100...
output:
3 4 5 8 9 10 7 13 12 17 20 24 23 28 27 29 37 43 42 44 41 45 46 40 47 39 48 65 68 66 69 70 76 77 78 80 79 81 73 84 82 91 100 99 101 102 105 104 106 103 107 110 114 117 131 133 136 146 134 147 145 157 159 160 158 163 166 167 168 175 176 177 179 180 181 191 188 192 194 196 197 198 195 199 190 206 207 2...
result:
ok 2 cases.
Test #15:
score: 0
Accepted
time: 7ms
memory: 7584kb
input:
1078 0111011100111011000000110100010011001100100101011100111000110001110111110010111010110111010110001010100111101001110111010010000001000100110000000010000010111010101000000110101011011011000001100000011111010001010001101111011110111110000110111111111111101100110100011001110110111011111001110010110...
output:
3 10 11 12 13 14 15 9 31 17 32 30 35 36 37 39 40 43 45 47 48 49 46 50 69 68 71 70 72 73 76 87 86 88 89 77 92 94 97 98 99 96 100 101 104 110 111 112 113 114 109 137 153 149 166 174 177 179 180 188 191 189 192 197 193 198 199 200 196 201 195 202 204 206 208 207 216 217 219 220 226 228 227 230 233 234 ...
result:
ok 2 cases.
Test #16:
score: 0
Accepted
time: 0ms
memory: 6400kb
input:
1310 0110101010101111001001001110010101000100000000011001001110111010011000110110010000001110111100110100110110110000011001000101100100000011011111011100010001101111001100100000011100111111101101001011000101000011100101111011100101011111000100101110011110001101110110100111101101011000000000101000101...
output:
3 4 20 17 22 23 21 25 26 28 27 33 35 36 37 49 50 57 61 62 75 76 74 77 63 85 120 122 121 133 134 142 136 143 144 145 141 146 151 147 152 153 156 161 183 187 193 194 196 195 215 214 217 218 216 219 220 226 227 225 228 229 230 222 231 224 236 240 247 248 249 252 253 258 259 266 267 272 273 274 271 275 ...
result:
ok 2 cases.
Test #17:
score: 0
Accepted
time: 8ms
memory: 6980kb
input:
1542 0000100001001001100011001101100001110111010111001110111110011011001000110010001111000000100011101001000100000001111001110100110101101111000011100010000100000111010001010110101110000001000001110100101111100001110010111000111001010111011100100100111011010101001100100101110110011000001011001000011...
output:
13 17 16 22 21 26 27 29 32 35 34 36 37 38 41 42 44 43 47 46 50 60 61 62 65 63 66 67 64 68 48 73 76 80 77 81 84 86 89 87 90 92 93 94 88 95 91 96 98 99 101 102 107 109 113 115 116 120 119 122 159 160 158 161 170 171 162 172 180 182 187 188 190 191 196 198 202 201 203 204 197 212 213 216 217 218 220 22...
result:
ok 2 cases.
Test #18:
score: 0
Accepted
time: 12ms
memory: 7736kb
input:
2000 0101010000001001011001110100110110001010001110110101101100010010011100000111001100000000110111011111100001110001111011101101110010100100001001110010001111011110011011010000100001011100000000110011000110010100101010110100001010101001111101011001110011010001100110000110101110000001000101001101010...
output:
2 5 6 9 28 29 31 33 38 39 36 40 41 42 50 67 83 84 85 66 89 90 91 94 95 99 101 96 108 109 110 113 119 114 121 123 124 125 126 127 128 122 133 135 131 140 141 156 159 161 162 165 166 170 171 172 168 173 174 175 185 183 186 189 197 187 198 199 202 200 203 204 210 206 211 209 212 213 214 215 207 216 227...
result:
ok 1 cases.
Test #19:
score: 0
Accepted
time: 12ms
memory: 7688kb
input:
2000 0100001100010101000111011110110000001010100001111010011110111010011101000001100111011101101100000100100011001100011101011110101011101000010000000001010110001100011111100011010110101010001100011100011100000111011011100010110010100001111101011001010111111101011100111011110001101000111100110101000...
output:
6 8 9 2 12 14 24 35 36 43 44 45 48 52 51 60 65 67 69 70 71 72 73 75 74 76 77 64 78 100 94 104 106 109 110 112 113 111 116 115 124 127 128 129 130 132 131 141 145 144 146 152 173 167 174 175 176 172 177 178 179 180 181 183 184 191 192 195 204 205 207 208 210 211 235 236 238 240 242 243 245 246 247 24...
result:
ok 1 cases.
Test #20:
score: 0
Accepted
time: 12ms
memory: 7704kb
input:
2000 0110101010100011101110010101000111001011110000101111001110111111100111000101010001110111000110110001010000010101101001011001111111011111111111011111000011100001111110000101100100000110100100100110110010000101101101100100001101100010011100000011110000100100011110111001101001101100110111011101011...
output:
2 7 3 9 8 10 12 64 61 67 66 68 69 70 71 73 74 65 76 77 78 85 86 89 91 92 98 99 106 105 107 104 108 109 110 111 103 112 119 120 125 121 126 129 132 134 135 130 136 133 137 144 145 149 152 151 155 154 156 157 153 158 161 160 162 169 170 175 176 186 185 187 184 189 188 190 193 196 191 198 199 224 225 2...
result:
ok 1 cases.
Test #21:
score: 0
Accepted
time: 8ms
memory: 7688kb
input:
2000 0110000110000000010000010011101111110001110101010000000001101110101010101001111001010100100101001100010100101000110001000101000101010011011000000100011110100001000010000111100110111010110001000100011100100011111001011011111011111001101101111011111011111010011100001111010001011101110000000001011...
output:
4 10 11 5 12 13 14 15 17 16 18 19 21 20 24 25 26 23 27 31 33 35 41 34 44 45 63 58 64 66 65 73 74 75 80 76 102 98 108 115 110 119 135 137 139 140 138 141 143 165 166 168 167 174 175 178 176 179 180 181 177 183 184 185 186 188 189 190 191 218 220 221 225 222 230 227 231 232 234 237 236 242 243 244 245...
result:
ok 1 cases.
Test #22:
score: 0
Accepted
time: 10ms
memory: 7692kb
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: 14ms
memory: 7760kb
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.