QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#469182 | #5280. Depot Rearrangement | Milkcat | 0 | 0ms | 0kb | C++20 | 1.6kb | 2024-07-09 15:38:33 | 2024-07-09 15:38:34 |
answer
#include <bits/stdc++.h>
#define REP(i, l, r) for (int i = (l); i <= (r); ++ i)
#define DEP(i, r, l) for (int i = (r); i >= (l); -- i)
#define fi first
#define se second
#define pb emplace_back
#define mems(x, v) memset((x), (v), sizeof(x))
using namespace std;
namespace Milkcat {
typedef long long LL;
typedef pair<LL, LL> pii;
const int N = 1005, M = 405;
int n, m, x, ct[N], in[N], rd[N], vs[N];
deque<int> r[M][M]; vector<int> G[N]; vector<pii> p, rs;
void dfs(int u) {
vs[u] = 1;
for (int &i = rd[u]; i < G[u].size(); ) {
int x = G[u][i ++];
dfs(x), p.pb(u, x);
}
}
void solve(int s) {
p.clear(), dfs(s);
if (!p.size()) return;
// for (auto [x, y] : p)
// cout << "QWQ " << x << ' ' << y << '\n';
int x = p[0].se, y = p.back().se - n, t = r[x][y].back();
r[x][y].pop_back(), r[x][y].emplace_front(n * m + 1), rs.pb(t, n * m + 1);
for (int i = 0; i < p.size(); i += 2) {
int x = p[i + 1].fi, y = p[i].fi - n, z = r[x][y].back();
rs.pb(z, t), t = z, r[x][y].pop_back();
}
}
int main() {
cin >> n >> m;
REP(i, 1, n) {
REP(j, 1, m) ct[j] = 0;
REP(j, 1, m) {
cin >> x, ct[x] ++;
if (ct[x] > 1) G[i].pb(x + n), in[x + n] ++, r[i][x].pb((i - 1) * m + j);
}
REP(j, 1, m)
if (!ct[j]) G[j + n].pb(i), in[i] ++;
}
// REP(i, 1, n) if ((G[i].size() + in[i]) & 1) cout << "Dick\n", exit(-1);
REP(i, 1, n) if (!vs[i]) solve(i);
cout << rs.size() << '\n';
for (auto [x, y] : rs)
cout << x << ' ' << y << '\n';
return 0;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T = 1;
while (T --) Milkcat::main();
return 0;
}
詳細信息
Test #1:
score: 0
Memory Limit Exceeded
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:
Test #2:
score: 0
Memory Limit Exceeded
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 4 21 20 4 12 20 19 12 8 19 15 8 7 15 18 7 3 18 14 3 2 14 10 2 21 10
result:
Test #3:
score: 0
Memory Limit Exceeded
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 3 101 89 3 56 89 79 56 50 79 100 50 58 100 67 58 97 67 30 97 90 30 49 90 39 49 29 39 95 29 66 95 20 66 38 20 44 38 76 44 36 76 75 36 55 75 28 55 87 28 27 87 6 27 18 6 43 18 26 43 16 26 101 16
result:
Test #4:
score: 0
Memory Limit Exceeded
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 109 1001 819 109 949 819 359 949 775 359 670 775 830 670 175 830 210 175 850 210 734 850 713 734 453 713 184 453 814 184 1001 814 707 1001 747 707 1001 747
result:
Test #5:
score: 0
Memory Limit Exceeded
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 273 20001 16173 273 16836 16173 18846 16836 17999 18846 12991 17999 18491 12991 14288 18491 9050 14288 8472 9050 12872 8472 18272 12872 10590 18272 16496 10590 17396 16496 696 17396 13396 696 10190 13396 9072 10190 14250 9072 1488 14250 10488 1488 18488 10488 18091 18488 14691 18091 16619 14691 ...
result:
Test #6:
score: 0
Memory Limit Exceeded
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 4 4021 3899 4 3920 3899 3960 3920 3918 3960 4000 3918 3980 4000 3940 3980 3917 3940 3999 3917 4020 3999 3800 4020 3979 3800 4016 3979 3760 4016 3978 3760 4015 3978 3957 4015 3860 3957 3915 3860 3658 3915 3936 3658 3994 3936 3935 3994 3914 3935 3992 3914 4013 3992 3880 4013 3898 3880 3932 3898 3...
result:
Test #7:
score: 0
Memory Limit Exceeded
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 1262 90001 72662 1262 75733 72662 37143 75733 87877 37143 84877 87877 35684 84877 60545 35684 87208 60545 88791 87208 5865 88791 40307 5865 69710 40307 15410 69710 49695 15410 15495 49695 5807 15495 16382 5807 22382 16382 80196 22382 22296 80196 88665 22296 86091 88665 67162 86091 23362 67162 56...
result:
Test #8:
score: 0
Memory Limit Exceeded
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 40 12041 12040 40 11720 12040 12000 11720 11680 12000 11960 11680 11640 11960 11920 11640 11600 11920 11880 11600 11560 11880 11840 11560 11520 11840 11800 11520 11480 11800 12039 11480 11400 12039 11440 11400 11999 11440 11399 11999 11959 11399 11360 11959 11919 11360 11320 11919 11879 11320 ...
result:
Test #9:
score: 0
Memory Limit Exceeded
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 47 40001 39588 47 39998 39588 39699 39998 39799 39699 40000 39799 39600 40000 39797 39600 39997 39797 39900 39997 39996 39900 39899 39996 39995 39899 39499 39995 39795 39499 39698 39795 39994 39698 39898 39994 39697 39898 39794 39697 39993 39794 39896 39993 39400 39896 39793 39400 39000 39793 ...
result:
Test #10:
score: 0
Memory Limit Exceeded
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 17 6401 5423 17 5600 5423 6080 5600 4320 6080 6240 4320 6400 6240 5439 6400 4639 5439 5119 4639 6399 5119 5436 6399 5117 5436 5920 5117 4159 5920 5435 4159 6393 5435 4800 6393 5598 4800 6238 5598 4638 6238 6077 4638 5113 6077 6073 5113 6237 6073 4157 6237 5917 4157 6391 5917 6236 6391 5754 6236...
result:
Test #11:
score: 0
Memory Limit Exceeded
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 9 40001 39882 9 39499 39882 40000 39499 39700 40000 39899 39700 39796 39899 39897 39796 39998 39897 39896 39998 39697 39896 39997 39697 39795 39997 39198 39795 39894 39198 39793 39894 39598 39793 39696 39598 39498 39696 39596 39498 39892 39596 39693 39892 39996 39693 39398 39996 39300 39398 39...
result:
Test #12:
score: 0
Memory Limit Exceeded
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 20 6021 5300 20 6020 5300 5700 6020 5980 5700 5680 5980 5960 5680 5660 5960 6018 5660 5939 6018 5640 5939 5920 5640 5619 5920 5900 5619 5599 5900 5880 5599 5580 5880 5820 5580 5560 5820 5800 5560 5540 5800 5760 5540 5480 5760 6017 5480 5398 6017 5440 5398 6000 5440 5380 6000 5420 5380 5979 5420...
result:
Test #13:
score: 0
Memory Limit Exceeded
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 162 90001 88193 162 89395 88193 89996 89395 88500 89996 89699 88500 90000 89699 88800 90000 89698 88800 87900 89698 89100 87900 87600 89100 89099 87600 89697 89099 89999 89697 89696 89999 89998 89696 88799 89998 89097 88799 88498 89097 89995 88498 89694 89995 88496 89694 89692 88496 89993 8969...
result:
Test #14:
score: 0
Memory Limit Exceeded
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 201 80401 79194 201 79600 79194 80000 79600 79199 80000 79999 79199 80400 79999 78800 80400 79198 78800 80398 79198 79998 80398 78799 79998 79599 78799 79997 79599 78400 79997 79196 78400 79996 79196 78798 79996 79995 78798 80397 79995 78000 80397 79597 78000 78797 79597 80393 78797 79596 8039...
result:
Test #15:
score: 0
Memory Limit Exceeded
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 784 160001 118784 784 160001 118784 2922 160001 147572 2922 133420 147572 87336 133420 132109 87336 148555 132109 134930 148555 126916 134930 143716 126916 110130 143716 119755 110130 53963 119755 117163 53963 139563 117163 138000 139563 152588 138000 133788 152588 34188 133788 103196 34188 3439...
result:
Test #16:
score: 0
Memory Limit Exceeded
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 134 60201 58993 134 59194 58993 59994 59194 59800 59994 60000 59800 59600 60000 59996 59600 58599 59996 59799 58599 59596 59799 59993 59596 59797 59993 59400 59797 59198 59400 59992 59198 58598 59992 59991 58598 59196 59991 59399 59196 59193 59399 60200 59193 59595 60200 59990 59595 59796 5999...
result:
Test #17:
score: 0
Memory Limit Exceeded
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 201 80401 80400 201 79600 80400 78800 79600 79599 78800 80000 79599 80399 80000 78400 80399 79598 78400 80397 79598 79998 80397 78399 79998 78799 78399 80396 78799 79596 80396 79997 79596 79595 79997 78398 79595 80395 78398 78000 80395 80394 78000 77600 80394 80393 77600 77200 80393 80392 7720...
result:
Test #18:
score: 0
Memory Limit Exceeded
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 129 120001 115797 129 117889 115797 119978 117889 116097 119978 120000 116097 119700 120000 119398 119700 119999 119398 118499 119999 119699 118499 119100 119699 118800 119100 119096 118800 118200 119096 119997 118200 118497 119997 119993 118497 119093 119993 119694 119093 119092 119694 119693...
result:
Test #19:
score: 0
Memory Limit Exceeded
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 333 132868 130869 333 132468 130869 132867 132468 132069 132867 132865 132069 131670 132865 132467 131670 131669 132467 132864 131669 131271 132864 132466 131271 130473 132466 132464 130473 131270 132464 132862 131270 130872 132862 132861 130872 130073 132861 132463 130073 130072 132463 13285...
result:
Test #20:
score: 0
Memory Limit Exceeded
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 193 160001 155105 193 154800 155105 159594 154800 159999 159594 158800 159999 159197 158800 160000 159197 159592 160000 159195 159592 158399 159195 159591 158399 157999 159591 158798 157999 159998 158798 158795 159998 159997 158795 158398 159997 158794 158398 156400 158794 158397 156400 159996...