QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#116713 | #5280. Depot Rearrangement | Liuxizai | 100 ✓ | 17ms | 15648kb | C++14 | 2.3kb | 2023-06-29 21:12:26 | 2023-06-29 21:12:28 |
Judging History
answer
#include<bits/stdc++.h>
#define File(name) freopen(#name".in", "r", stdin); freopen(#name".out", "w", stdout);
using namespace std;
using ll = long long;
using ull = unsigned long long;
template<typename T>
inline T read(){
T n = 0; int f = 1; char ch = getchar();
while(!isdigit(ch)){
if(ch == '-') f = -1;
ch = getchar();
}
while(isdigit(ch)){
n = n * 10 + ch - '0';
ch = getchar();
}
return f * n;
}
template<typename T>
void write(T n){
if(n/10) write(n/10);
putchar(n%10+'0');
}
void input() {}
template<typename Type, typename... Types>
void input(Type &arg, Types&... args){
arg = read<Type>();
input(args...);
}
namespace Main{
const int N = 405;
int n, m;
vector<int> pos[N][N], res;
vector<int> g[N<<1];
vector<pair<int, int>> ans;
void dfs(int u){
while(!g[u].empty()){
int v = g[u].back(); g[u].pop_back();
dfs(v);
res.push_back(u);
}
}
void Main(){
input(n, m);
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
int x;
input(x);
pos[i][x - 1].push_back(i * m + j + 1);
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(pos[i][j].size() == 0) g[n + j].push_back(i);
else for(int k = 1; k < pos[i][j].size(); k++) g[i].push_back(n + j);
}
}
for(int i = 0; i < n; i++){
res.clear();
dfs(i);
assert(res.size() % 2 == 0);
int lst = n * m + 1;
for(int i = 0; i < res.size(); i += 2){
ans.emplace_back(pos[res[i + 1]][res[i] - n].back(), lst);
lst = pos[res[i + 1]][res[i] - n].back();
pos[res[i + 1]][res[i] - n].pop_back();
}
if(lst != n * m + 1) ans.emplace_back(n * m + 1, lst);
}
write(ans.size()); puts("");
for(pair<int, int> x: ans) write(x.first), putchar(' '), write(x.second), puts("");
return;
}
} // namespace
int main(){
#ifdef Liuxizai
freopen("in", "r", stdin);
freopen("out", "w", stdout);
#endif // Liuxizai
Main::Main();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 2ms
memory: 7416kb
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:
0
result:
ok both subtasks are correct!
Test #2:
score: 5
Accepted
time: 1ms
memory: 7340kb
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 10 21 4 10 15 4 8 15 14 8 3 14 20 3 7 20 19 7 12 19 18 12 2 18 21 2
result:
ok both subtasks are correct!
Test #3:
score: 5
Accepted
time: 2ms
memory: 7252kb
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 18 101 38 18 29 38 76 29 30 76 90 30 49 90 39 49 20 39 43 20 6 43 28 6 67 28 56 67 66 56 75 66 36 75 16 36 27 16 87 27 97 87 55 97 50 55 26 50 100 26 58 100 79 58 44 79 95 44 89 95 3 89 101 3
result:
ok both subtasks are correct!
Test #4:
score: 5
Accepted
time: 1ms
memory: 7264kb
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:
19 453 1001 184 453 734 184 713 734 819 713 359 819 775 359 175 775 210 175 830 210 670 830 850 670 814 850 949 814 109 949 1001 109 747 1001 707 747 1001 707
result:
ok both subtasks are correct!
Test #5:
score: 5
Accepted
time: 2ms
memory: 7868kb
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:
195 13073 20001 12213 13073 10354 12213 8254 10354 16367 8254 13167 16367 6867 13167 5967 6867 7667 5967 2067 7667 16854 2067 7854 16854 4955 7854 3641 4955 3971 3641 3334 3971 5034 3334 17871 5034 459 17871 1541 459 17469 1541 1569 17469 10541 1569 8875 10541 475 8875 12259 475 1488 12259 5159 1488...
result:
ok both subtasks are correct!
Test #6:
score: 5
Accepted
time: 3ms
memory: 7316kb
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 84 4021 53 84 37 53 80 37 98 80 258 98 29 258 4 29 60 4 171 60 211 171 107 211 331 107 104 331 358 104 34 358 18 34 40 18 12 40 140 12 155 140 417 155 93 417 169 93 70 169 198 70 380 198 88 380 78 88 100 78 499 100 55 499 39 55 178 39 144 178 129 144 51 129 313 51 357 313 436 357 130 436 194 13...
result:
ok both subtasks are correct!
Test #7:
score: 5
Accepted
time: 4ms
memory: 9948kb
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:
205 72662 90001 11820 72662 72720 11820 75733 72720 37143 75733 68130 37143 22642 68130 36376 22642 38476 36376 39588 38476 77388 39588 69294 77388 1916 69294 55164 1916 13556 55164 85710 13556 20910 85710 42644 20910 44971 42644 53371 44971 26373 53371 19174 26373 85356 19174 31656 85356 76686 3165...
result:
ok both subtasks are correct!
Test #8:
score: 5
Accepted
time: 4ms
memory: 8160kb
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 360 12041 80 360 400 80 120 400 440 120 160 440 480 160 200 480 520 200 240 520 560 240 280 560 600 280 40 600 680 40 602 680 79 602 679 79 119 679 720 119 159 720 760 159 199 760 800 199 239 800 840 239 279 840 880 279 301 880 719 301 359 719 759 359 399 759 799 399 439 799 839 439 479 839 87...
result:
ok both subtasks are correct!
Test #9:
score: 5
Accepted
time: 7ms
memory: 8956kb
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 196 40001 249 196 172 249 96 172 489 96 793 489 1181 793 1099 1181 242 1099 1373 242 381 1373 57 381 600 57 480 600 97 480 482 97 1681 482 345 1681 163 345 1593 163 639 1593 1771 639 2169 1771 783 2169 1998 783 571 1998 139 571 2266 139 337 2266 2993 337 2687 2993 761 2687 287 761 158 287 2899...
result:
ok both subtasks are correct!
Test #10:
score: 5
Accepted
time: 3ms
memory: 7508kb
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 338 6401 137 338 2009 137 977 2009 806 977 182 806 40 182 353 40 234 353 839 234 1034 839 510 1034 750 510 1119 750 1428 1119 2238 1428 17 2238 757 17 276 757 396 276 1025 396 938 1025 281 938 73 281 192 73 2805 192 1640 2805 765 1640 2337 765 1581 2337 1804 1581 1560 1804 534 1560 3288 534 241...
result:
ok both subtasks are correct!
Test #11:
score: 5
Accepted
time: 7ms
memory: 9048kb
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 495 40001 794 495 170 794 397 170 159 397 982 159 253 982 186 253 1183 186 558 1183 483 558 1362 483 550 1362 1097 550 577 1097 393 577 298 393 1825 298 866 1825 1684 866 892 1684 374 892 592 374 293 592 1877 293 1970 1877 1265 1970 353 1265 300 353 2159 300 2041 2159 90 2041 311 90 195 311 32...
result:
ok both subtasks are correct!
Test #12:
score: 5
Accepted
time: 3ms
memory: 7692kb
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 340 6021 40 340 360 40 60 360 380 60 79 380 400 79 100 400 420 100 140 420 439 140 159 439 460 159 179 460 500 179 219 500 520 219 259 520 540 259 280 540 560 280 300 560 602 300 20 602 640 20 39 640 660 39 59 660 680 59 77 680 740 77 97 740 760 97 120 760 780 120 138 780 800 138 158 800 820 15...
result:
ok both subtasks are correct!
Test #13:
score: 5
Accepted
time: 1ms
memory: 10644kb
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 1710 90001 597 1710 1962 597 861 1962 2525 861 712 2525 212 712 1651 212 3254 1651 231 3254 2020 231 3228 2020 1014 3228 5664 1014 974 5664 2552 974 6099 2552 1458 6099 100 1458 1243 100 487 1243 660 487 1590 660 53 1590 7588 53 3504 7588 218 3504 840 218 567 840 1094 567 1244 1094 1673 1244 1...
result:
ok both subtasks are correct!
Test #14:
score: 5
Accepted
time: 14ms
memory: 11872kb
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 689 80401 201 689 1197 201 200 1197 1608 200 1206 1608 199 1206 2010 199 1205 2010 804 1205 603 804 1607 603 803 1607 1606 803 197 1606 2466 197 1204 2466 602 1204 2009 602 802 2009 2008 802 196 2008 3216 196 1203 3216 2007 1203 1605 2007 599 1605 2412 599 195 2412 1004 195 2411 1004 2006 2411...
result:
ok both subtasks are correct!
Test #15:
score: 5
Accepted
time: 5ms
memory: 12260kb
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:
217 118784 160001 784 118784 160001 784 11722 160001 2922 11722 147572 2922 133420 147572 87336 133420 132109 87336 90155 132109 48288 90155 62732 48288 19769 62732 71849 19769 132724 71849 49916 132724 119484 49916 6527 119484 129727 6527 84927 129727 119327 84927 49884 119327 45116 49884 36387 451...
result:
ok both subtasks are correct!
Test #16:
score: 5
Accepted
time: 4ms
memory: 9680kb
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 2980 60201 290 2980 793 290 284 793 1397 284 563 1397 1396 563 595 1396 1749 595 1934 1749 1374 1934 2334 1374 3392 2334 134 3392 1987 134 766 1987 4989 766 2183 4989 5383 2183 109 5383 2600 109 587 2600 6305 587 2798 6305 574 2798 3184 574 572 3184 2970 572 759 2970 3162 759 6545 3162 253 654...
result:
ok both subtasks are correct!
Test #17:
score: 5
Accepted
time: 15ms
memory: 12756kb
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 915 80401 201 915 1206 201 804 1206 402 804 1205 402 200 1205 1861 200 803 1861 603 803 1608 603 199 1608 2010 199 802 2010 1607 802 1204 1607 602 1204 2009 602 198 2009 2412 198 197 2412 2814 197 196 2814 3550 196 195 3550 3618 195 194 3618 4020 194 193 4020 4422 193 192 4422 4824 192 191 482...
result:
ok both subtasks are correct!
Test #18:
score: 5
Accepted
time: 13ms
memory: 12332kb
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 427 120001 1692 427 392 1692 690 392 421 690 3291 421 1496 3291 124 1496 775 124 4136 775 825 4136 4124 825 1404 4124 600 1404 4679 600 806 4679 1656 806 1436 1656 253 1436 2642 253 1216 2642 372 1216 2215 372 5395 2215 3874 5395 5697 3874 4322 5697 5682 4322 4607 5682 243 4607 2390 243 8290 2...
result:
ok both subtasks are correct!
Test #19:
score: 5
Accepted
time: 17ms
memory: 15648kb
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 1330 132868 999 1330 748 999 1328 748 666 1328 333 666 1665 333 665 1665 1663 665 998 1663 1662 998 1327 1662 332 1327 2386 332 663 2386 1998 663 997 1998 1997 997 1661 1997 330 1661 2331 330 329 2331 2663 329 662 2663 2330 662 1326 2330 3046 1326 661 3046 2662 661 996 2662 2661 996 1325 2661...
result:
ok both subtasks are correct!
Test #20:
score: 5
Accepted
time: 17ms
memory: 14164kb
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 2388 160001 569 2388 1228 569 523 1228 391 523 546 391 1984 546 4380 1984 1074 4380 1540 1074 1901 1540 2332 1901 5423 2332 2676 5423 11280 2676 2953 11280 1162 2953 776 1162 1033 776 11751 1033 3876 11751 13326 3876 4724 13326 147 4724 2968 147 2064 2968 1914 2064 14091 1914 2632 14091 15984 ...
result:
ok both subtasks are correct!