QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#125887#5280. Depot Rearrangementdengtingyu51 33ms24884kbC++141.5kb2023-07-17 21:00:412023-07-17 21:00:45

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-17 21:00:45]
  • 评测
  • 测评结果:51
  • 用时:33ms
  • 内存:24884kb
  • [2023-07-17 21:00:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 810
ll n,m;
ll a[N];
vector<ll>t[N];
ll fir[N],v[N*N],nxt[N*N],w[N*N];ll cnt=0; 
inline void add(ll x,ll y,ll z){
	v[++cnt]=y;w[cnt]=z;nxt[cnt]=fir[x];fir[x]=cnt;
	return ;
}
bool vis[N];
ll xu[N],cn=0;
inline void dfs(ll x){
	vis[x]=1;
	for(;fir[x];){
		ll o=v[fir[x]];ll p=fir[x];
		fir[x]=nxt[fir[x]];dfs(o);
		xu[++cn]=p;
	}return ;
} 
ll x[N*N],y[N*N],cnn=0;
ll tt[N*N];ll ji=0;
ll jit[N];
int main()
{
//	freopen("test1.in","r",stdin);
	//freopen(".in","r",stdin);
//	freopen("test1.out","w",stdout);
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>m;ll g=n*m+1;for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)t[j].clear();
		for(int j=1;j<=m;j++){
			cin>>a[j];tt[++ji]=a[j];t[a[j]].push_back(j);
		}for(int j=1;j<=m;j++){
			if(t[j].empty()){
				add(j+n,i,0);continue;
			}for(int k=1;k<t[j].size();k++)add(i,j+n,t[j][k]+(i-1)*m);
		}
	}for(int i=1;i<=n;i++){
		if(vis[i])continue;
		cn=0;dfs(i);if(!cn)continue;
		reverse(xu+1,xu+cn+1);
		assert(v[xu[cn]]==i);
		reverse(xu+1,xu+cn);
		x[++cnn]=w[xu[1]];y[cnn]=g;
		for(int i=3;i<=cn;i+=2){
			x[++cnn]=w[xu[i-2]];y[cnn]=w[xu[i]];
		}x[++cnn]=g;y[cnn]=w[xu[cn-1]];
	}cout<<cnn<<'\n';
	for(int i=1;i<=cnn;i++){
		cout<<x[i]<<' '<<y[i]<<'\n';swap(tt[x[i]],tt[y[i]]);
	}/*for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			jit[tt[(i-1)*m+j]]++;
		}for(int j=1;j<=m;j++){
			if(jit[j]!=i){
				cout<<1;
			}
			assert(jit[j]==i);
		}
	}*/
	return 0;
}

詳細信息

Test #1:

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

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: 2ms
memory: 9600kb

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

result:

ok both subtasks are correct!

Test #3:

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

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

result:

ok both subtasks are correct!

Test #4:

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

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

result:

ok both subtasks are correct!

Test #5:

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

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
13073 12213
12213 10354
10354 8254
8254 16367
16367 13167
13167 6867
6867 5967
5967 7667
7667 2067
2067 16854
16854 7854
7854 4955
4955 3641
3641 3971
3971 3334
3334 5034
5034 17871
17871 459
459 1541
1541 17469
17469 1569
1569 10541
10541 8875
8875 475
475 12259
12259 1488
1488 5159...

result:

ok both subtasks are correct!

Test #6:

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

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
1110 4021
1110 1511
1511 1079
1079 926
926 1386
1386 1071
1071 1364
1364 641
641 1089
1089 1118
1118 1281
1281 1528
1528 776
776 976
976 1097
1097 757
757 994
994 763
763 809
809 963
963 730
730 1345
1345 1395
1395 731
731 931
931 760
760 1207
1207 975
975 673
673 961
961 1289
1289 1125
1125 89...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #7:

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

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
72662 11820
11820 72720
72720 75733
75733 37143
37143 68130
68130 22642
22642 36376
36376 38476
38476 39588
39588 77388
77388 69294
69294 1916
1916 55164
55164 13556
13556 85710
85710 20910
20910 42644
42644 44971
44971 53371
53371 26373
26373 19174
19174 85356
85356 31656
31656 7668...

result:

ok both subtasks are correct!

Test #8:

score: 0
Wrong Answer
time: 4ms
memory: 10576kb

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
1747 12041
1747 343
343 2441
2441 19875
19875 4260
4260 502
502 5638
5638 2636
2636 667
667 1709
1709 6335
6335 3415
3415 2292
2292 16861
16861 5802
5802 5329
5329 382
382 5796
5796 19841
19841 7119
7119 539
539 8436
8436 2632
2632 1335
1335 1744
1744 4881
4881 3410
3410 4192
4192 2405
2405 71...

result:

wrong answer Integer 19875 violates the range [1, 12041]

Test #9:

score: 2
Acceptable Answer
time: 6ms
memory: 10724kb

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
2726 40001
2726 2225
2225 2911
2911 1723
1723 1525
1525 141
141 873
873 305
305 2222
2222 1586
1586 3145
3145 1796
1796 1938
1938 1741
1741 1351
1351 2438
2438 4031
4031 2292
2292 3785
3785 2615
2615 1368
1368 1816
1816 1957
1957 1298
1298 4191
4191 1948
1948 2656
2656 3134
3134 2297
2297 5660...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #10:

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

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
1458 6401
1458 1599
1599 1238
1238 2258
2258 1854
1854 2254
2254 527
527 2119
2119 1644
1644 1721
1721 1653
1653 1138
1138 2271
2271 1675
1675 1010
1010 1357
1357 1418
1418 543
543 2317
2317 1907
1907 1613
1613 1711
1711 2579
2579 1388
1388 2576
2576 2530
2530 369
369 1140
1140 1486
1486 545
54...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #11:

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

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
957 40001
957 2632
2632 2417
2417 2973
2973 3852
3852 4851
4851 324
324 4054
4054 4983
4983 3048
3048 960
960 5362
5362 3053
3053 3725
3725 4134
4134 602
602 468
468 2203
2203 1116
1116 3134
3134 1112
1112 617
617 2967
2967 325
325 2903
2903 8111
8111 2575
2575 1865
1865 2192
2192 6983
6983 63...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #12:

score: 0
Wrong Answer
time: 2ms
memory: 12060kb

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
4230 6021
4230 2089
2089 3683
3683 1350
1350 2483
2483 2961
2961 3210
3210 1764
1764 2343
2343 2754
2754 123
123 440
440 4290
4290 2993
2993 3520
3520 1182
1182 1547
1547 5005
5005 3465
3465 627
627 4291
4291 1381
1381 1548
1548 2533
2533 1457
1457 2102
2102 3471
3471 1362
1362 1979
1979 2956
2...

result:

wrong answer Integer 6589 violates the range [1, 6021]

Test #13:

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

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
4135 90001
4135 1123
1123 25112
25112 2604
2604 19173
19173 39
39 11312
11312 4154
4154 16141
16141 6099
6099 20484
20484 13989
13989 12843
12843 7253
7253 12841
12841 13763
13763 16385
16385 5655
5655 6117
6117 6327
6327 685
685 5207
5207 49
49 6318
6318 17939
17939 14189
14189 6334
6334 1089...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #14:

score: 0
Wrong Answer
time: 14ms
memory: 18984kb

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
2906 80401
2906 47
47 19717
19717 357
357 20970
20970 7955
7955 19070
19070 47611
47611 21584
21584 19692
19692 17179
17179 20929
20929 12067
12067 89019
89019 19027
19027 12711
12711 21562
21562 17142
17142 2627
2627 12367
12367 2977
2977 1966
1966 20980
20980 13979
13979 47088
47088 88993
88...

result:

wrong answer Integer 89019 violates the range [1, 80401]

Test #15:

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

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
118784 784
160001 784
11722 160001
11722 2922
2922 147572
147572 133420
133420 87336
87336 132109
132109 90155
90155 48288
48288 62732
62732 19769
19769 71849
71849 132724
132724 49916
49916 119484
119484 6527
6527 129727
129727 84927
84927 119327
119327 49884
49884 45116
45116 363...

result:

ok both subtasks are correct!

Test #16:

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

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
15196 60201
15196 3303
3303 7717
7717 3320
3320 7723
7723 4056
4056 9103
9103 4086
4086 16957
16957 18347
18347 9104
9104 32861
32861 28389
28389 16636
16636 2385
2385 15530
15530 12514
12514 11859
11859 25712
25712 16635
16635 11554
11554 4717
4717 31170
31170 34445
34445 4712
4712 16483
1648...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #17:

score: 0
Wrong Answer
time: 12ms
memory: 21480kb

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
73615 80401
73615 822
822 15504
15504 1636
1636 3110
3110 4679
4679 1263
1263 103047
103047 2110
2110 3503
3503 2454
2454 45847
45847 2492
2492 74579
74579 2871
2871 5108
5108 15534
15534 3033
3033 45733
45733 146433
146433 823
823 20954
20954 1265
1265 23277
23277 46629
46629 7379
7379 46517
...

result:

wrong answer Integer 103047 violates the range [1, 80401]

Test #18:

score: 2
Acceptable Answer
time: 17ms
memory: 18604kb

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
18720 120001
18720 20225
20225 17854
17854 22142
22142 6861
6861 1299
1299 7921
7921 11790
11790 22140
22140 5222
5222 18718
18718 6683
6683 8343
8343 18093
18093 5610
5610 18721
18721 15919
15919 495
495 7703
7703 22353
22353 1732
1732 18099
18099 3891
3891 36186
36186 723
723 29099
29099 413...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #19:

score: 0
Wrong Answer
time: 33ms
memory: 24884kb

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
15892 132868
15892 8685
8685 4538
4538 12482
12482 26230
26230 4190
4190 47678
47678 26191
26191 47601
47601 22802
22802 2862
2862 12823
12823 4525
4525 13498
13498 3530
3530 13870
13870 22769
22769 13824
13824 3205
3205 32467
32467 2874
2874 32445
32445 29734
29734 3856
3856 3209
3209 21450
...

result:

wrong answer Integer 137974 violates the range [1, 132868]

Test #20:

score: 2
Acceptable Answer
time: 17ms
memory: 17468kb

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
23353 160001
23353 14148
14148 14160
14160 14153
14153 15545
15545 31946
31946 6374
6374 37097
37097 2223
2223 3082
3082 15290
15290 20808
20808 34782
34782 26109
26109 9477
9477 29976
29976 2228
2228 41607
41607 611
611 13667
13667 16130
16130 40239
40239 7495
7495 9149
9149 33944
33944 20810...

result:

points 0.40 first subtask is correct but plan is wrong.