QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#116195 | #5280. Depot Rearrangement | Irisu# | 75 | 40ms | 28088kb | C++17 | 1.5kb | 2023-06-28 11:56:55 | 2024-05-31 18:20:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;++i)
#define per(i,a,b) for(int i=(a),i##end=(b);i>=i##end;--i)
#define pb push_back
typedef vector<int>vi;
typedef pair<int,int>pii;
int n,m,A[405*405];
vi pos[405][405];
int ecnt,h[805];
struct edges{
int nxt,to;
}E[405*405*2];
void addline(int u,int v){
E[++ecnt]={h[u],v},h[u]=ecnt;
}
vi path;
bool vis[805];
void dfs(int u){
vis[u]=1;
for(int&i=h[u];i;){
int v=E[i].to;
i=E[i].nxt;
dfs(v);
}
path.pb(u);
}
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
cin>>n>>m;
rep(i,1,n*m)cin>>A[i];
rep(i,1,n){
vi vis(m+1,0);
rep(j,1,m){
int x=A[(i-1)*m+j];
if(!vis[x]){
vis[x]=1;
}else{
pos[i][x].pb((i-1)*m+j);
addline(i,n+x);
}
}
rep(x,1,m){
if(!vis[x]){
addline(n+x,i);
}
}
}
vector<pii>as;
rep(s,1,n)if(!vis[s]){
path.clear();
dfs(s);
reverse(path.begin(),path.end());
vi cir;
for(int i=1;i<(int)path.size();i+=2){
int u=path[i-1];
int x=path[i]-n;
// printf("#buk %d, val %d\n",u,x);
cir.pb(pos[u][x].back());
pos[u][x].pop_back();
}
as.pb({n*m+1,cir.back()});
per(i,cir.size()-1,1){
as.pb({cir[i],cir[i-1]});
}
as.pb({n*m+1,cir[0]});
}
cout<<as.size()<<endl;
for(auto[x,y]:as)cout<<x<<' '<<y<<endl;
return 0;
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
10 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3
output:
result:
Test #2:
score: 5
Accepted
time: 2ms
memory: 7804kb
input:
5 4 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4
output:
13 21 10 10 2 2 14 14 7 7 15 15 3 3 18 18 8 8 19 19 12 12 20 20 4 21 4
result:
ok both subtasks are correct!
Test #3:
score: 5
Accepted
time: 2ms
memory: 8740kb
input:
10 10 8 10 10 3 7 3 5 6 1 4 3 8 2 9 1 8 4 2 7 3 10 7 9 2 1 10 10 9 1 2 9 7 4 5 2 9 10 5 7 6 6 8 6 8 4 2 9 1 2 8 6 1 4 2 2 1 5 6 3 10 10 7 9 4 8 9 8 2 5 6 4 3 1 6 3 3 10 7 7 5 3 6 8 5 9 4 6 7 9 4 10 5 3 4 5 1 1 7 8 5
output:
32 101 18 18 26 26 16 16 43 43 27 27 87 87 3 3 28 28 75 75 55 55 36 36 20 20 38 38 44 44 76 76 89 89 49 49 39 39 29 29 95 95 66 66 97 97 30 30 90 90 56 56 50 50 100 100 58 58 79 79 67 67 6 101 6
result:
ok both subtasks are correct!
Test #4:
score: 0
Runtime Error
input:
100 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 9 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10...
output:
result:
Test #5:
score: 0
Runtime Error
input:
200 100 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 ...
output:
result:
Test #6:
score: 5
Accepted
time: 0ms
memory: 10012kb
input:
201 20 20 18 5 5 1 7 8 17 12 10 20 12 13 19 16 2 9 8 20 20 19 10 17 20 9 11 15 17 9 2 3 4 17 10 7 20 7 19 17 11 20 2 1 13 11 9 11 6 10 8 11 3 2 16 9 15 16 12 13 6 5 13 4 13 3 8 20 18 10 3 14 1 11 20 17 17 2 11 20 1 4 10 3 3 9 13 7 10 19 16 14 16 9 19 14 15 12 9 20 12 2 19 18 2 7 7 2 12 10 8 20 18 16...
output:
1401 4021 47 47 28 28 64 64 29 29 4 4 84 84 33 33 164 164 88 88 51 51 344 344 34 34 168 168 36 36 92 92 53 53 206 206 104 104 70 70 37 37 231 231 11 11 262 262 74 74 126 126 106 106 76 76 210 210 245 245 38 38 303 303 290 290 252 252 93 93 144 144 384 384 369 369 306 306 446 446 326 326 107 107 525 ...
result:
ok both subtasks are correct!
Test #7:
score: 0
Runtime Error
input:
300 300 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 ...
output:
result:
Test #8:
score: 5
Accepted
time: 8ms
memory: 11564kb
input:
301 40 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
11624 12041 322 322 42 42 362 362 82 82 402 402 122 122 442 442 162 162 482 482 202 202 522 522 242 242 562 562 2 2 642 642 602 602 43 43 643 643 83 83 682 682 123 123 722 722 163 163 762 762 203 203 802 802 243 243 842 842 282 282 683 683 323 323 723 723 363 363 763 763 403 403 803 803 443 443 843 ...
result:
ok both subtasks are correct!
Test #9:
score: 5
Accepted
time: 8ms
memory: 12180kb
input:
400 100 11 65 1 79 15 18 79 46 9 30 71 53 58 55 94 73 39 16 6 91 49 30 23 30 28 81 90 48 97 54 79 30 94 18 42 77 44 36 5 48 55 97 79 36 41 59 79 71 32 59 3 10 63 52 44 41 9 46 31 31 56 87 60 80 12 51 15 78 41 65 95 34 29 83 46 64 37 53 98 17 41 45 36 73 20 53 48 80 57 54 57 72 39 56 98 6 10 78 11 72...
output:
14592 40001 512 512 113 113 7 7 206 206 22 22 210 210 118 118 319 319 24 24 1005 1005 215 215 713 713 31 31 125 125 418 418 613 613 218 218 128 128 715 715 32 32 513 513 329 329 129 129 33 33 917 917 130 130 34 34 133 133 219 219 40 40 520 520 230 230 136 136 330 330 720 720 627 627 138 138 920 920 ...
result:
ok both subtasks are correct!
Test #10:
score: 5
Accepted
time: 0ms
memory: 10140kb
input:
40 160 17 2 3 4 5 6 7 91 9 10 154 12 103 14 15 16 17 25 19 58 21 8 23 24 52 26 27 58 120 105 50 55 104 32 35 36 37 38 45 10 41 42 43 44 45 71 47 48 49 34 140 52 53 54 115 44 28 58 59 60 61 62 63 64 132 66 67 68 69 70 71 69 24 74 75 76 77 133 79 80 81 82 100 84 31 86 87 88 100 90 91 92 93 94 95 96 97...
output:
1316 6401 338 338 1936 1936 977 977 806 806 182 182 1328 1328 2105 2105 17 17 831 831 666 666 189 189 504 504 1174 1174 28 28 192 192 40 40 353 353 1470 1470 45 45 2417 2417 195 195 839 839 705 705 52 52 1178 1178 714 714 56 56 366 366 1803 1803 205 205 1340 1340 226 226 841 841 229 229 1631 1631 58...
result:
ok both subtasks are correct!
Test #11:
score: 5
Accepted
time: 4ms
memory: 11416kb
input:
400 100 88 82 9 2 90 1 83 32 32 79 8 79 63 67 85 82 50 63 69 2 7 91 21 90 69 3 39 78 66 83 96 53 24 65 56 63 90 54 35 55 94 22 76 12 54 55 5 49 91 73 8 19 64 54 39 23 13 27 34 4 81 52 13 11 36 45 3 50 82 81 42 50 75 15 99 70 29 26 70 66 34 15 42 83 16 19 19 12 76 1 68 49 7 17 64 37 98 34 99 37 34 64...
output:
14611 40001 119 119 1115 1115 9 9 132 132 12 12 311 311 16 16 207 207 18 18 134 134 20 20 507 507 317 317 24 24 820 820 138 138 329 329 709 709 140 140 25 25 331 331 30 30 603 603 419 419 36 36 141 141 339 339 1314 1314 727 727 430 430 37 37 905 905 340 340 45 45 1421 1421 341 341 208 208 347 347 14...
result:
ok both subtasks are correct!
Test #12:
score: 5
Accepted
time: 7ms
memory: 10392kb
input:
301 20 8 1 1 1 1 1 1 17 1 9 1 5 1 1 1 1 13 1 9 1 18 1 1 16 1 15 5 19 1 8 11 10 1 1 1 1 18 4 1 1 1 1 16 1 1 1 12 10 1 1 1 14 11 13 1 1 1 1 1 1 10 1 1 1 1 1 1 19 14 1 1 1 5 1 1 1 1 13 1 18 1 1 4 1 1 1 1 1 1 1 1 1 1 16 16 10 1 14 18 1 1 1 7 1 1 1 1 6 9 1 13 1 1 1 2 1 1 1 1 1 1 10 1 1 1 17 1 10 10 1 12 ...
output:
4260 6021 322 322 23 23 343 343 42 42 362 362 63 63 383 383 82 82 402 402 123 123 423 423 143 143 445 445 162 162 482 482 203 203 502 502 3 3 522 522 242 242 544 544 262 262 602 602 4 4 622 622 25 25 642 642 44 44 665 665 64 64 723 723 84 84 742 742 102 102 763 763 124 124 784 784 144 144 802 802 5 ...
result:
ok both subtasks are correct!
Test #13:
score: 5
Accepted
time: 15ms
memory: 14352kb
input:
300 300 215 159 263 206 201 183 286 56 142 10 231 214 34 54 263 250 169 208 239 148 104 22 244 17 74 68 184 52 2 30 42 83 222 106 25 152 37 225 213 213 69 273 91 221 207 48 166 28 221 50 46 64 10 254 207 109 206 144 270 291 195 197 253 235 141 186 102 68 52 24 38 6 181 44 256 200 77 233 285 163 223 ...
output:
32648 90001 631 631 15 15 309 309 1213 1213 312 312 40 40 916 916 49 49 945 945 1813 1813 962 962 53 53 332 332 55 55 2726 2726 637 637 335 335 644 644 350 350 648 648 2730 2730 354 354 660 660 360 360 1521 1521 1816 1816 361 361 57 57 966 966 68 68 363 363 2148 2148 1217 1217 970 970 366 366 69 69 ...
result:
ok both subtasks are correct!
Test #14:
score: 5
Accepted
time: 32ms
memory: 20172kb
input:
201 400 1 1 1 1 1 152 1 1 1 1 1 1 1 33 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 300 154 1 1 147 1 1 1 383 186 1 1 90 256 1 1 1 1 1 1 1 63 1 1 1 1 208 1 1 1 1 31 1 1 1 1 1 1 1 127 1 1 29 216 397 393 1 1 1 1 1 1 279 1 1 1 1 55 1 1 215 249 1 1 1 1 1 1 172 1 1 1 1 1 1 1 1 1 1 1 1 349 1 331 1 1 1 1 1 1 1 34...
output:
63990 80401 404 404 2 2 802 802 3 3 1602 1602 1203 1203 4 4 2002 2002 1204 1204 803 803 405 405 1603 1603 804 804 1604 1604 5 5 2402 2402 1205 1205 406 406 2003 2003 7 7 809 809 2004 2004 1605 1605 408 408 2404 2404 8 8 3202 3202 1206 1206 2005 2005 409 409 810 810 2802 2802 9 9 1208 1208 811 811 24...
result:
ok both subtasks are correct!
Test #15:
score: 0
Runtime Error
input:
400 400 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 ...
output:
result:
Test #16:
score: 5
Accepted
time: 4ms
memory: 11664kb
input:
301 200 50 129 146 60 183 51 47 77 26 73 1 45 1 44 149 1 81 196 17 16 163 35 159 71 1 94 161 138 138 27 76 1 102 42 5 186 176 1 111 198 37 63 81 155 95 164 132 135 155 194 126 98 31 34 121 19 175 148 33 105 25 122 91 165 1 69 1 197 12 98 1 155 5 53 42 1 60 98 78 61 155 13 1 171 102 152 95 61 87 200 ...
output:
23506 60201 1228 1228 220 220 621 621 13 13 221 221 1234 1234 2808 2808 16 16 231 231 3208 3208 232 232 4812 4812 25 25 627 627 405 405 244 244 29 29 630 630 416 416 824 824 417 417 633 633 1246 1246 637 637 5235 5235 246 246 1011 1011 1247 1247 419 419 250 250 830 830 438 438 252 252 6224 6224 253 ...
result:
ok both subtasks are correct!
Test #17:
score: 5
Accepted
time: 27ms
memory: 22896kb
input:
201 400 1 1 1 1 1 1 1 1 1 1 1 1 1 263 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 246 1 1 1 1 1 1 1 1 1 1 1 1 1 1 107 1 1 1 1 1 1 1 1 57 1 1 1 1 1 1 1 224 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 90 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
77869 80401 802 802 2 2 1202 1202 803 803 402 402 1203 1203 3 3 1604 1604 804 804 404 404 1605 1605 4 4 2002 2002 5 5 2402 2402 6 6 2802 2802 7 7 3202 3202 8 8 3602 3602 9 9 4002 4002 10 10 4402 4402 11 11 4802 4802 12 12 5202 5202 13 13 5602 5602 15 15 6003 6003 16 16 6402 6402 17 17 6802 6802 18 1...
result:
ok both subtasks are correct!
Test #18:
score: 5
Accepted
time: 20ms
memory: 16624kb
input:
400 300 75 26 289 176 131 196 124 8 230 157 247 265 13 2 210 141 17 200 187 83 21 22 118 144 232 26 284 75 48 30 132 32 65 34 72 36 73 286 164 40 41 261 65 270 221 12 139 48 49 143 91 39 17 258 275 56 151 194 282 55 228 266 296 64 22 232 67 142 69 152 10 102 109 45 75 49 283 112 78 283 81 236 169 22...
output:
43105 120001 615 615 1552 1552 1216 1216 617 617 1241 1241 26 26 323 323 28 28 3616 3616 43 43 325 325 48 48 337 337 1554 1554 53 53 5138 5138 645 645 1555 1555 1248 1248 351 351 1253 1253 354 354 1259 1259 924 924 65 65 2444 2444 1269 1269 372 372 66 66 1556 1556 647 647 75 75 649 649 1823 1823 156...
result:
ok both subtasks are correct!
Test #19:
score: 5
Accepted
time: 40ms
memory: 28088kb
input:
333 399 1 1 1 1 1 1 1 28 1 1 1 1 1 1 161 1 17 1 1 1 1 262 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 43 1 1 1 1 1 70 1 1 1 142 1 1 1 1 1 1 1 1 1 1 1 1 70 1 1 1 1 1 1 278 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 245 1 1 1 1 1 1 33 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 106 1 1 1 1 268 1 1 1 172 1 1 1 1 1 312 1 286 1 1 1 1 ...
output:
114795 132868 1199 1199 800 800 401 401 1200 1200 404 404 2 2 1598 1598 405 405 1599 1599 801 801 1600 1600 1201 1201 3 3 1997 1997 406 406 1998 1998 1601 1601 4 4 2000 2000 5 5 2397 2397 407 407 2398 2398 6 6 2796 2796 408 408 2001 2001 802 802 2399 2399 803 803 2797 2797 7 7 3194 3194 409 409 3196...
result:
ok both subtasks are correct!
Test #20:
score: 5
Accepted
time: 36ms
memory: 19940kb
input:
400 400 100 35 353 385 317 228 7 148 113 165 11 306 209 89 21 166 17 2 19 249 27 305 377 22 3 353 38 28 29 96 191 32 33 309 35 308 100 176 152 40 176 42 43 86 45 46 96 48 396 381 218 246 53 54 334 159 243 360 294 60 33 62 185 64 65 66 191 121 351 107 10 343 367 74 75 201 77 247 79 134 304 92 42 126 ...
output:
55816 160001 430 430 2828 2828 26 26 433 433 35 35 856 856 37 37 461 461 1228 1228 2033 2033 41 41 464 464 47 47 1247 1247 4837 4837 61 61 468 468 1630 1630 863 863 67 67 2428 2428 867 867 2064 2064 874 874 1634 1634 2831 2831 470 470 878 878 83 83 1255 1255 2434 2434 1651 1651 485 485 87 87 492 492...
result:
ok both subtasks are correct!