QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#116700#5280. Depot RearrangementLiuxizai100 ✓512ms23580kbC++142.3kb2023-06-29 20:26:302023-06-29 20:26:33

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-29 20:26:33]
  • 评测
  • 测评结果:100
  • 用时:512ms
  • 内存:23580kb
  • [2023-06-29 20:26:30]
  • 提交

answer

// 有点怀疑这代码的正确性

#include<bits/stdc++.h>
#define int long long

using namespace std;

inline int read() {
    int f = 1;
    int res = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        res = res * 10 + ch - '0';
        ch = getchar();
    }
    return res * f;
}

const int maxn = 410;

int n, m;
vector < int > pos[maxn][maxn];//用 vector 实现,不然会 MLE
int tot[maxn][maxn];

struct node {
    int from;
    int to;
    int next;
}
edge[maxn * maxn * 2];
int head[maxn << 1];
int cnt;

void add(int u, int v) {
    edge[++cnt].to = v;
    edge[cnt].from = u;
    edge[cnt].next = head[u];
    head[u] = cnt;
}

int que[maxn * maxn * 2], tag;
bool vis[maxn * maxn * 2];

void dfs(int now) {
    for (int i = head[now]; i; i = edge[i].next) {
        if (vis[i])
            continue;
        int v = edge[i].to;
        vis[i] = true;
        dfs(v);
        que[++tag] = i;
    }
}

struct ANS {
    int x;
    int y;
}
ans[maxn * maxn + maxn];
int len;

signed main() {
    n = read(), m = read();
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            int x = read();
            ++tot[i][x];
            pos[i][x].push_back((i - 1) * m + j);
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            for (int k = 1; k < tot[i][j]; k++) {
                add(i, j + n);
            }
            if (tot[i][j] < 1)
                add(j + n, i);
        }
    }
    for (int i = n + 1; i <= n + m; i++) {
        tag = 0;
        dfs(i);
        int to = n * m + 1;
        for (int i = 1; i <= tag; i++) {
            int u = edge[que[i]].from;
            int v = edge[que[i]].to;
            if (u <= n) {
                ans[++len].x = pos[u][v - n][--tot[u][v - n]];
                ans[len].y = to;
                to = ans[len].x;
            }
        }
        if (tag) {
            ans[++len].x = n * m + 1;
            ans[len].y = to;
        }
    }
    printf("%lld\n", len);
    for (int i = 1; i <= len; i++) {
        printf("%lld %lld\n", ans[i].x, ans[i].y);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 3ms
memory: 11700kb

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: 11916kb

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
10 4
3 10
15 3
8 15
14 8
2 14
20 2
7 20
19 7
12 19
18 12
21 18

result:

ok both subtasks are correct!

Test #3:

score: 5
Accepted
time: 0ms
memory: 12088kb

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
29 101
6 29
18 6
38 18
76 38
30 76
90 30
49 90
20 49
3 20
28 3
16 28
43 16
39 43
56 39
36 56
67 36
75 67
66 75
97 66
55 97
50 55
27 50
87 27
26 87
100 26
58 100
79 58
44 79
95 44
89 95
101 89

result:

ok both subtasks are correct!

Test #4:

score: 5
Accepted
time: 0ms
memory: 12720kb

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
819 1001
359 819
775 359
175 775
949 175
109 949
453 109
184 453
814 184
210 814
830 210
670 830
850 670
734 850
713 734
1001 713
747 1001
707 747
1001 707

result:

ok both subtasks are correct!

Test #5:

score: 5
Accepted
time: 4ms
memory: 12384kb

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
16367 20001
13167 16367
6867 13167
5967 6867
18140 5967
4190 18140
3798 4190
4233 3798
11277 4233
8977 11277
5861 8977
3761 5861
12259 3761
1488 12259
14288 1488
9050 14288
14250 9050
3013 14250
12213 3013
10354 12213
7854 10354
4955 7854
3641 4955
3971 3641
3334 3971
5034 3334
17871 5034
459 17...

result:

ok both subtasks are correct!

Test #6:

score: 5
Accepted
time: 2ms
memory: 12276kb

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
80 4021
29 80
4 29
84 4
53 84
37 53
18 37
60 18
171 60
34 171
12 34
40 12
258 40
98 258
358 98
211 358
107 211
331 107
104 331
155 104
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
20 178
140 20
144 140
129 144
51 129
313 51
357 313
436 357
130 436
...

result:

ok both subtasks are correct!

Test #7:

score: 5
Accepted
time: 4ms
memory: 15036kb

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
73649 90001
26374 73649
16773 26374
30110 16773
15410 30110
49695 15410
15495 49695
5807 15495
16382 5807
22382 16382
80196 22382
22296 80196
88665 22296
19994 88665
82027 19994
19927 82027
79980 19927
66480 79980
81409 66480
83209 81409
68242 83209
51930 68242
75843 51930
37143 75843
87877 3714...

result:

ok both subtasks are correct!

Test #8:

score: 5
Accepted
time: 16ms
memory: 12048kb

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
360 40
80 360
400 80
120 400
440 120
160 440
480 160
200 480
520 200
240 520
560 240
280 560
600 280
39 600
680 39
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 ...

result:

ok both subtasks are correct!

Test #9:

score: 5
Accepted
time: 17ms
memory: 16260kb

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
1593 40001
249 1593
172 249
96 172
196 96
242 196
57 242
489 57
793 489
1181 793
381 1181
480 381
97 480
600 97
1373 600
345 1373
163 345
99 163
482 99
1681 482
1099 1681
639 1099
1771 639
2169 1771
783 2169
1998 783
571 1998
139 571
900 139
437 900
67 437
496 67
2266 496
337 2266
2993 337
268...

result:

ok both subtasks are correct!

Test #10:

score: 5
Accepted
time: 2ms
memory: 11764kb

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
2009 6401
977 2009
806 977
182 806
40 182
338 40
137 338
353 137
234 353
839 234
1034 839
1428 1034
2238 1428
17 2238
510 17
750 510
276 750
73 276
757 73
1119 757
938 1119
281 938
396 281
1025 396
2417 1025
155 2417
192 155
2805 192
1640 2805
765 1640
2337 765
1581 2337
1804 1581
2065 1804
861...

result:

ok both subtasks are correct!

Test #11:

score: 5
Accepted
time: 6ms
memory: 16228kb

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
170 40001
397 170
159 397
794 159
558 794
483 558
982 483
253 982
186 253
1183 186
90 1183
495 90
1362 495
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
20 2159
311 20
195 311
329 19...

result:

ok both subtasks are correct!

Test #12:

score: 5
Accepted
time: 6ms
memory: 11636kb

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
340 20
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
18 602
640 18
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
...

result:

ok both subtasks are correct!

Test #13:

score: 5
Accepted
time: 39ms
memory: 19540kb

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
1962 90001
861 1962
212 861
1710 212
597 1710
2525 597
231 2525
1651 231
3254 1651
712 3254
1014 712
100 1014
2020 100
3228 2020
974 3228
5664 974
1458 5664
53 1458
1243 53
487 1243
660 487
1590 660
2552 1590
6099 2552
3504 6099
218 3504
840 218
296 840
1094 296
1244 1094
1673 1244
1955 1673
5...

result:

ok both subtasks are correct!

Test #14:

score: 5
Accepted
time: 138ms
memory: 21640kb

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
689 201
200 689
1197 200
199 1197
1608 199
1206 1608
197 1206
2010 197
1205 2010
804 1205
603 804
1607 603
803 1607
1606 803
196 1606
2466 196
1204 2466
602 1204
2009 602
802 2009
2008 802
195 2008
3216 195
1203 3216
2007 1203
1605 2007
599 1605
2412 599
193 2412
1004 193
2411 1004
2...

result:

ok both subtasks are correct!

Test #15:

score: 5
Accepted
time: 7ms
memory: 16900kb

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
158790 160001
25190 158790
16377 25190
20540 16377
128398 20540
24189 128398
132716 24189
5558 132716
94758 5558
81124 94758
115533 81124
30342 115533
127476 30342
7076 127476
128520 7076
11594 128520
34906 11594
11306 34906
54355 11306
10755 54355
86379 10755
10779 86379
128794 10779
6920 12879...

result:

ok both subtasks are correct!

Test #16:

score: 5
Accepted
time: 29ms
memory: 14816kb

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
290 60201
793 290
284 793
1397 284
134 1397
2980 134
563 2980
1396 563
595 1396
1749 595
1934 1749
1374 1934
2334 1374
3392 2334
109 3392
1987 109
766 1987
4989 766
2183 4989
5383 2183
92 5383
2600 92
587 2600
6305 587
2798 6305
574 2798
3184 574
572 3184
2970 572
759 2970
3162 759
6545 3162
2...

result:

ok both subtasks are correct!

Test #17:

score: 5
Accepted
time: 226ms
memory: 21892kb

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
915 201
200 915
1206 200
804 1206
402 804
1205 402
199 1205
1861 199
803 1861
603 803
1608 603
198 1608
2010 198
802 2010
1607 802
1204 1607
602 1204
2009 602
197 2009
2412 197
196 2412
2814 196
195 2814
3550 195
194 3550
3618 194
193 3618
4020 193
192 4020
4422 192
191 4422
4824 191...

result:

ok both subtasks are correct!

Test #18:

score: 5
Accepted
time: 66ms
memory: 20456kb

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
2642 120001
1436 2642
124 1436
427 124
1692 427
392 1692
690 392
253 690
775 253
421 775
3291 421
1496 3291
4136 1496
825 4136
4124 825
1404 4124
600 1404
4679 600
806 4679
1656 806
4607 1656
243 4607
2215 243
5395 2215
3874 5395
5697 3874
1216 5697
372 1216
4322 372
5682 4322
1139 5682
5011 1...

result:

ok both subtasks are correct!

Test #19:

score: 5
Accepted
time: 512ms
memory: 23580kb

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
1330 333
999 1330
748 999
1328 748
666 1328
332 666
1665 332
665 1665
1663 665
998 1663
1662 998
1327 1662
330 1327
2386 330
663 2386
1998 663
997 1998
1997 997
1661 1997
329 1661
2331 329
327 2331
2663 327
662 2663
2330 662
1326 2330
3046 1326
661 3046
2662 661
996 2662
2661 996
1...

result:

ok both subtasks are correct!

Test #20:

score: 5
Accepted
time: 97ms
memory: 22064kb

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
1984 391
147 1984
546 147
1074 546
1540 1074
1901 1540
2332 1901
4380 2332
2676 4380
5423 2676
2953 5423
11280 2953
3876 11280
1162 3876
776 1162
1033 776
287 1033
2968 287
136 2968
1580 136
3160 1580
2064 3160
1914 2064
11751 1914
4724 11751
1332...

result:

ok both subtasks are correct!