QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#116117#5280. Depot Rearrangementlcjlcj#75 23ms28520kbC++201.7kb2023-06-28 09:55:472024-05-31 14:20:49

Judging History

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

  • [2024-05-31 14:20:49]
  • 评测
  • 测评结果:75
  • 用时:23ms
  • 内存:28520kb
  • [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:55:47]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
const int maxn=805; 

int n,m;
int ecnt; 
vector<pair<int,int>> g[maxn+5]; 
vector<int> cnt[maxn+5][maxn+5];
vector<pair<int,int>> ans;
int sta[maxn*maxn+5],top;
int cur[maxn+5],vis[maxn+5],flg[maxn*maxn+5],flg2[maxn*maxn+5]; 
void dfs(int u) {
    vis[u]=1; 
    for (int &i=cur[u];i<g[u].size();i++) {
        int v=g[u][i].first,w=g[u][i].second;
        if (w<0) {
            if (flg2[-w]) continue ; 
            flg2[-w]=1; 
        }
        else {
            if (flg[w]) continue ; 
            flg[w]=1; 
        }
        dfs(v); 
        if (w>0) sta[++top]=w; 
    }
}
void makeswap(int u,int v) {
    ans.emplace_back(u,v); 
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m;
    for (int i=1;i<=n;i++) {
        for (int j=1;j<=m;j++) {
            int t;
            cin>>t;
            int id=(i-1)*m+j; 
            cnt[i][t].emplace_back(id); 
        }
        
        for (int j=1;j<=m;j++) {
            if (cnt[i][j].size()==0) {
                g[i].emplace_back(j+n,--ecnt); 
            } else if (cnt[i][j].size()>=2) {
                for (int k=0;k<cnt[i][j].size()-1;k++) {
                    g[j+n].emplace_back(i,cnt[i][j][k]); 
                }
            }
        }
    }
    int lst=n*m+1; 
    for (int i=n+1;i<=n+m;i++) {
        if (!vis[i]) {
            top=0; 
            dfs(i);
            if (top==1) continue ; 
            makeswap(sta[top],lst);
            for (int j=top;j>=2;j--) makeswap(sta[j-1],sta[j]);
            makeswap(lst,sta[1]);
        }
    }
    cout<<ans.size()<<'\n';
    for (auto [x,y]:ans) cout<<x<<' '<<y<<'\n'; 
    return 0; 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3652kb

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:

6
0 31
31 0
0 31
31 0
0 31
31 0

result:

wrong answer first subtask is incorrect

Test #2:

score: 5
Accepted
time: 1ms
memory: 3676kb

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
1 21
6 1
11 6
2 11
13 2
3 13
17 3
7 17
18 7
14 18
9 14
19 9
21 19

result:

ok both subtasks are correct!

Test #3:

score: 5
Accepted
time: 1ms
memory: 3660kb

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
25 101
4 25
13 4
34 13
52 34
32 52
11 32
41 11
72 41
24 72
86 24
96 86
46 96
92 46
51 92
12 51
2 12
23 2
95 23
31 95
42 31
78 42
44 78
21 44
82 21
54 82
63 54
75 63
85 75
26 85
65 26
101 65

result:

ok both subtasks are correct!

Test #4:

score: 0
Wrong Answer
time: 1ms
memory: 4144kb

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:

21
451 1001
183 451
733 183
711 733
811 711
202 811
825 202
172 825
772 172
665 772
844 665
812 844
352 812
942 352
101 942
1001 101
746 1001
706 746
1001 706
0 1001
1001 706

result:

wrong answer first subtask is incorrect

Test #5:

score: 0
Wrong Answer
time: 3ms
memory: 5620kb

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:

223
16301 20001
12708 16301
6329 12708
12729 6329
7922 12729
13422 7922
19312 13422
13412 19312
11608 13412
18908 11608
16308 18908
2001 16308
16801 2001
11030 16801
3430 11030
15424 3430
3179 15424
1855 3179
3155 1855
1879 3155
7549 1879
1849 7549
3424 1849
16130 3424
16830 16130
7804 16830
404 780...

result:

wrong answer first subtask is incorrect

Test #6:

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

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
72 4021
48 72
138 48
143 138
65 143
35 65
144 35
7 144
83 7
227 83
105 227
249 105
123 249
148 123
26 148
3 26
224 3
9 224
150 9
44 150
142 44
91 142
42 91
106 42
244 106
25 244
167 25
356 167
101 356
261 101
463 261
104 463
62 104
46 62
327 46
254 327
267 254
289 267
274 289
184 274
464 184
18...

result:

ok both subtasks are correct!

Test #7:

score: 0
Wrong Answer
time: 9ms
memory: 10092kb

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:

515
0 90001
90001 0
73502 90001
26249 73502
16718 26249
17416 16718
80416 17416
65716 80416
58284 65716
3130 58284
77830 3130
20226 77830
21726 20226
65784 21726
16516 65784
30072 16516
15407 30072
49635 15407
15435 49635
5789 15435
16204 5789
22204 16204
80115 22204
22215 80115
88504 22215
19866 88...

result:

wrong answer first subtask is incorrect

Test #8:

score: 5
Accepted
time: 5ms
memory: 6968kb

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
1 12041
302 1
603 302
2 603
604 2
904 604
3 904
905 3
303 905
906 303
1206 906
4 1206
1207 4
304 1207
1208 304
605 1208
1209 605
1506 1209
5 1506
1507 5
305 1507
1508 305
606 1508
1509 606
907 1509
1510 907
1807 1510
6 1807
1808 6
306 1808
1809 306
607 1809
1810 607
908 1810
1811 908
1210 1811...

result:

ok both subtasks are correct!

Test #9:

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

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
878 40001
19 878
149 19
1518 149
220 1518
9 220
550 9
1571 550
372 1571
2012 372
735 2012
3281 735
242 3281
52 242
740 52
2323 740
3420 2323
803 3420
1 803
226 1
422 226
327 422
2335 327
223 2335
141 223
315 141
484 315
1622 484
3527 1622
2336 3527
153 2336
1038 153
4306 1038
337 4306
410 337
...

result:

ok both subtasks are correct!

Test #10:

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

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
481 6401
644 481
2242 644
1444 2242
2722 1444
1286 2722
1448 1286
483 1448
10 483
1921 10
803 1921
2882 803
2724 2882
1928 2724
807 1928
9 807
331 9
1289 331
1614 1289
3682 1614
2401 3682
2088 2401
3750 2088
1 3750
702 1
1452 702
805 1452
175 805
3804 175
1778 3804
3842 1778
2730 3842
3374 2730...

result:

ok both subtasks are correct!

Test #11:

score: 5
Accepted
time: 9ms
memory: 9656kb

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
6 40001
432 6
4 432
739 4
129 739
501 129
26 501
911 26
228 911
922 228
11 922
307 11
937 307
529 937
136 529
949 136
362 949
652 362
590 652
456 590
1026 456
601 1026
532 601
1242 532
1346 1242
527 1346
21 527
626 21
925 626
57 925
109 57
955 109
239 955
1803 239
550 1803
1261 550
958 1261
56...

result:

ok both subtasks are correct!

Test #12:

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

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
2 6021
226 2
541 226
3 541
603 3
4 603
663 4
5 663
1432 5
6 1432
841 6
7 841
122 7
302 122
605 302
907 605
9 907
422 9
11 422
341 11
13 341
221 13
908 221
583 908
606 583
781 606
14 781
1741 14
15 1741
94 15
303 94
1506 303
16 1506
21 16
304 21
1807 304
305 1807
171 305
306 171
10 306
842 10
30...

result:

ok both subtasks are correct!

Test #13:

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

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
931 90001
1804 931
942 1804
4714 942
10 4714
3624 10
302 3624
974 302
53 974
1896 53
152 1896
2105 152
4662 2105
127 4662
910 127
1514 910
3302 1514
4805 3302
1955 4805
3029 1955
1376 3029
4831 1376
3211 4831
3930 3211
5879 3930
5109 5879
6603 5109
4777 6603
3685 4777
2704 3685
6620 2704
2143 ...

result:

ok both subtasks are correct!

Test #14:

score: 5
Accepted
time: 11ms
memory: 17784kb

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
1 80401
403 1
2 403
414 2
806 414
3 806
809 3
404 809
1207 404
4 1207
1208 4
202 1208
1409 202
405 1409
1410 405
606 1410
1609 606
5 1609
1610 5
203 1610
1810 203
406 1810
1811 406
608 1811
2011 608
7 2011
2012 7
204 2012
2213 204
408 2213
2215 408
609 2215
2409 609
8 2409
2416 8
409 2416
3017...

result:

ok both subtasks are correct!

Test #15:

score: 0
Wrong Answer
time: 15ms
memory: 14500kb

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:

703
158401 160001
25065 158401
36562 25065
150411 36562
36411 150411
16162 36411
20427 16162
16027 20427
139791 16027
110991 139791
75791 110991
24991 75791
16253 24991
113853 16253
8903 113853
24903 8903
88529 24903
39207 88529
70407 39207
58929 70407
21729 58929
62529 21729
19729 62529
71712 19729...

result:

wrong answer first subtask is incorrect

Test #16:

score: 5
Accepted
time: 8ms
memory: 11416kb

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
11 60201
442 11
139 442
426 139
35 426
478 35
1318 478
13 1318
814 13
518 814
248 518
617 248
16 617
817 16
213 817
905 213
56 905
406 56
82 406
245 82
696 245
1020 696
1650 1020
216 1650
20 216
675 20
1808 675
621 1808
2101 621
633 2101
316 633
659 316
69 659
760 69
227 760
1022 227
2683 1022...

result:

ok both subtasks are correct!

Test #17:

score: 5
Accepted
time: 20ms
memory: 19392kb

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
1 80401
604 1
1006 604
2 1006
805 2
202 805
1007 202
403 1007
1207 403
3 1207
1208 3
203 1208
1408 203
404 1408
1409 404
605 1409
1609 605
4 1609
1610 4
204 1610
1601 204
405 1601
1810 405
606 1810
2011 606
5 2011
2012 5
205 2012
2212 205
406 2212
2213 406
607 2213
2413 607
6 2413
2414 6
206 2...

result:

ok both subtasks are correct!

Test #18:

score: 5
Accepted
time: 23ms
memory: 17860kb

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
932 120001
692 932
223 692
1006 223
4511 1006
304 4511
2101 304
14 2101
4503 14
1505 4503
4803 1505
685 4803
161 685
392 161
2402 392
6303 2402
5115 6303
4063 5115
8432 4063
2438 8432
762 2438
594 762
8546 594
5431 8546
2863 5431
9445 2863
3359 9445
4726 3359
355 4726
5527 355
9603 5527
4201 9...

result:

ok both subtasks are correct!

Test #19:

score: 5
Accepted
time: 22ms
memory: 28520kb

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
1 132868
1001 1
334 1001
1298 334
2 1298
1666 2
3 1666
1999 3
4 1999
2332 4
335 2332
2665 335
5 2665
2998 5
6 2998
3331 6
7 3331
3665 7
9 3665
3997 9
10 3997
4330 10
336 4330
4663 336
11 4663
4996 11
12 4996
5663 12
13 5663
6328 13
337 6328
6661 337
14 6661
6994 14
16 6994
7327 16
338 7327
76...

result:

ok both subtasks are correct!

Test #20:

score: 5
Accepted
time: 23ms
memory: 22084kb

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
801 160001
25 801
1642 25
18 1642
406 18
2001 406
147 2001
1566 147
813 1566
215 813
413 215
802 413
3209 802
920 3209
11 920
2014 11
4404 2014
3202 4404
473 3202
1222 473
405 1222
7031 405
2403 7031
4227 2403
2401 4227
1606 2401
2670 1606
690 2670
71 690
3738 71
5201 3738
2632 5201
419 2632
2...

result:

ok both subtasks are correct!