QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#116088#5280. Depot Rearrangementhhoppitree#43 22ms22000kbC++141.2kb2023-06-28 09:13:352024-05-31 14:20:27

Judging History

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

  • [2024-05-31 14:20:27]
  • 评测
  • 测评结果:43
  • 用时:22ms
  • 内存:22000kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-28 09:13:35]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1005;

int ed, vis[N];
vector< pair<int, int> > G[N];
vector<int> z;

void dfs(int x)
{
    int v, w;
    while (G[x].size()) tie(v, w) = G[x].back(), G[x].pop_back(), dfs(v), w && (z.push_back(w), 0);
}

vector< pair<int, int> > tp;

void add()
{
    tp.push_back(make_pair(z[0], ed));
    for (int i = 1; i < z.size(); ++i) tp.push_back(make_pair(z[i], z[i - 1]));
    tp.push_back(make_pair(ed, z.back()));
    return;
}

signed main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    ed = n * m + 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1, x; j <= m; ++j) {
            scanf("%d", &x);
            if (vis[x]++) G[x].push_back(make_pair(m + i, (i - 1) * m + j));
        }
        for (int j = 1; j <= m; vis[j++] = 0) if (!vis[j])
            G[m + i].push_back(make_pair(j, 0));
    }
    for (int i = 1; i <= m + n; ++i) vis[i] = 0;
    for (int i = 1; i <= m; ++i) {
        if (G[i].size() && !vis[i]) {
            z.clear();
            dfs(i);
            add();
        }
    }
    printf("%d\n", tp.size());
    for (auto [x, y] : tp) printf("%d %d\n", x, y);
    return 0;
}

详细

Test #1:

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

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: 2
Acceptable Answer
time: 0ms
memory: 3920kb

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

result:

points 0.40 first subtask is correct but plan is wrong.

Test #3:

score: 2
Acceptable Answer
time: 0ms
memory: 3900kb

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

result:

points 0.40 first subtask is correct but plan is wrong.

Test #4:

score: 2
Acceptable Answer
time: 1ms
memory: 3824kb

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

result:

points 0.40 first subtask is correct but plan is wrong.

Test #5:

score: 2
Acceptable Answer
time: 1ms
memory: 3808kb

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
2067 20001
7667 2067
19198 7667
11277 19198
4233 11277
3761 4233
6061 3761
7562 6061
1858 7562
3158 1858
1892 3158
8079 1892
8590 8079
9190 8590
8579 9190
3192 8579
15492 3192
3444 15492
11044 3444
12753 11044
16366 12753
18966 16366
11653 18966
13480 11653
19380 13480
13453 19380
7953 13453
127...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #6:

score: 2
Acceptable Answer
time: 1ms
memory: 4156kb

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
140 4021
60 140
80 60
37 80
70 37
144 70
84 144
18 84
155 18
106 155
239 106
4 239
40 4
149 40
59 149
150 59
129 150
255 129
119 255
53 119
95 53
153 95
12 153
231 12
178 231
29 178
258 29
280 258
296 280
262 296
104 262
331 104
313 331
340 313
55 340
64 55
107 64
358 107
187 358
273 187
259 27...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #7:

score: 2
Acceptable Answer
time: 4ms
memory: 3980kb

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
9149 90001
19174 9149
26373 19174
53371 26373
44971 53371
81662 44971
72733 81662
75843 72733
51995 75843
6695 51995
64122 6695
40757 64122
38351 40757
41351 38351
38357 41351
40722 38357
63995 40722
46592 63995
29605 46592
71995 29605
12895 71995
73384 12895
51840 73384
25140 51840
85384 25140
...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #8:

score: 2
Acceptable Answer
time: 3ms
memory: 5780kb

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
604 12041
303 604
2 303
905 2
304 905
906 304
605 906
3 605
1207 3
305 1207
1208 305
606 1208
1209 606
907 1209
4 907
1507 4
306 1507
1508 306
607 1508
1509 607
908 1509
1510 908
1210 1510
5 1210
1808 5
307 1808
1809 307
608 1809
1810 608
909 1810
1811 909
1211 1811
1812 1211
1511 1812
6 1511
...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #9:

score: 2
Acceptable Answer
time: 0ms
memory: 6292kb

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
96 196
900 96
600 900
57 600
242 57
1571 242
395 1571
1593 395
740 1593
2037 740
2335 2037
777 2335
97 777
287 97
2336 287
337 2336
482 337
249 482
158 249
281 158
99 281
888 99
489 888
345 489
1193 345
849 1193
480 849
400 480
3285 400
1644 3285
3436 1644
1043 3436
172 1043
2362 172...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #10:

score: 2
Acceptable Answer
time: 1ms
memory: 4152kb

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
137 6401
338 137
40 338
534 40
1560 534
1428 1560
2805 1428
750 2805
2337 750
1581 2337
2906 1581
806 2906
2065 806
2774 2065
510 2774
3750 510
1631 3750
1366 1631
839 1366
1485 839
757 1485
17 757
3804 17
1876 3804
3835 1876
182 3835
938 182
2009 938
3453 2009
2819 3453
234 2819
2797 234
3887 ...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #11:

score: 2
Acceptable Answer
time: 5ms
memory: 6308kb

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
763 40001
20 763
495 20
90 495
996 90
67 996
311 67
51 311
937 51
577 937
159 577
592 159
659 592
483 659
532 483
629 532
1097 629
1274 1097
595 1274
949 595
170 949
1362 170
397 1362
955 397
642 955
63 642
953 63
253 953
1825 253
243 1825
988 243
132 988
93 132
574 93
976 574
1298 976
550 129...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #12:

score: 2
Acceptable Answer
time: 1ms
memory: 4648kb

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
545 6021
239 545
3 239
605 3
4 605
678 4
5 678
1435 5
6 1435
852 6
7 852
908 7
606 908
598 606
607 598
303 607
128 303
9 128
440 9
11 440
359 11
13 359
789 13
910 789
230 910
14 230
1760 14
15 1760
1508 15
304 1508
1808 304
609 1808
1810 609
305 1810
174 305
306 174
95 306
19 95
307 19
37 307
1...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #13:

score: 2
Acceptable Answer
time: 0ms
memory: 8688kb

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
597 90001
3698 597
1896 3698
1094 1896
231 1094
1955 231
53 1955
4748 53
2183 4748
218 2183
4750 218
5950 4750
5337 5950
1100 5337
100 1100
974 100
3211 974
2020 3211
4831 2020
3454 4831
3228 3454
6620 3228
2932 6620
2160 2932
6676 2160
4188 6676
1710 4188
1014 1710
5432 1014
3809 5432
4793 38...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #14:

score: 2
Acceptable Answer
time: 12ms
memory: 13836kb

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
404 80401
2 404
809 2
606 809
3 606
1208 3
405 1208
810 405
203 810
1410 203
406 1410
1209 406
4 1209
1610 4
608 1610
1210 608
811 1210
1411 811
204 1411
1811 204
408 1811
1613 408
5 1613
2012 5
609 2012
1812 609
1412 1812
812 1412
1616 812
1007 1616
1813 1007
206 1813
2215 206
409 2215
2013 4...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #15:

score: 2
Acceptable Answer
time: 7ms
memory: 3856kb

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
78790 160001
138790 78790
77865 138790
70529 77865
39329 70529
21773 39329
58973 21773
19849 58973
71933 19849
115542 71933
6920 115542
128794 6920
10779 128794
86379 10779
10755 86379
54355 10755
11306 54355
34906 11306
11594 34906
128520 11594
7076 128520
127476 7076
30342 127476
115533 30342
...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #16:

score: 2
Acceptable Answer
time: 8ms
memory: 7536kb

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
1356 60201
532 1356
165 532
505 165
73 505
518 73
13 518
621 13
316 621
528 316
924 528
311 924
1778 311
1090 1778
633 1090
1827 633
637 1827
2110 637
702 2110
221 702
875 221
106 875
848 106
200 848
471 200
168 471
325 168
706 325
349 706
2771 349
1039 2771
384 1039
94 384
785 94
357 785
1255...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #17:

score: 2
Acceptable Answer
time: 15ms
memory: 15920kb

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
1007 80401
605 1007
203 605
806 203
2 806
1208 2
404 1208
1008 404
204 1008
1409 204
405 1409
1209 405
3 1209
1610 3
606 1610
1210 606
807 1210
1410 807
205 1410
1810 205
406 1810
1611 406
4 1611
2012 4
607 2012
1612 607
1411 1612
808 1411
1614 808
1009 1614
1811 1009
1211 1811
1812 1211
206 1...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #18:

score: 2
Acceptable Answer
time: 16ms
memory: 10612kb

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
253 120001
775 253
1006 775
392 1006
4679 392
124 4679
427 124
243 427
690 243
5011 690
2450 5011
6592 2450
1692 6592
4726 1692
1139 4726
8546 1139
4136 8546
5160 4136
2215 5160
5527 2215
8696 5527
600 8696
873 600
2642 873
9516 2642
2865 9516
9608 2865
2370 9608
1185 2370
5336 1185
1216 5336
...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #19:

score: 2
Acceptable Answer
time: 22ms
memory: 22000kb

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
1333 132868
335 1333
1003 335
2 1003
1667 2
3 1667
2000 3
336 2000
2333 336
4 2333
2667 4
5 2667
2999 5
6 2999
3332 6
7 3332
3666 7
9 3666
3998 9
337 3998
4331 337
10 4331
4664 10
11 4664
4997 11
12 4997
5665 12
338 5665
6329 338
13 6329
6662 13
14 6662
6995 14
339 6995
7328 339
16 7328
7662 ...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #20:

score: 2
Acceptable Answer
time: 21ms
memory: 12976kb

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
287 160001
1074 287
546 1074
323 546
920 323
1580 920
1033 1580
3547 1033
147 3547
523 147
1228 523
496 1228
391 496
2250 391
94 2250
1162 94
4567 1162
690 4567
3365 690
1984 3365
4380 1984
2670 4380
1901 2670
2738 1901
7049 2738
2388 7049
5423 2388
3918 5423
328 3918
694 328
203 694
530 203
1...

result:

points 0.40 first subtask is correct but plan is wrong.