QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#117335#5280. Depot RearrangementAFewSuns95 15ms11544kbC++142.0kb2023-06-30 23:56:572023-06-30 23:56:58

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-30 23:56:58]
  • 评测
  • 测评结果:95
  • 用时:15ms
  • 内存:11544kb
  • [2023-06-30 23:56:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll long long
	#define bl bool
	ll my_pow(ll a,ll b,ll mod){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		return res;
	}
	ll qpow(ll a,ll b){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res*=a;
			a*=a;
			b>>=1;
		}
		return res;
	}
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define inf 8e18
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	il ll read(){
		ll sum=0,f=1;
		char ch=0;
		while(!isdigit(ch)){
			if(ch=='-') f=-1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch^48);
			ch=getchar();
		}
		return sum*f;
	}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
vector<ll> ans;
ll n,m,a[440],head[880],cnt=0;
bl ck[440],pd[880];
struct node{
	ll nxt,to,w;
}e[200020];
void add(ll u,ll v,ll ww){
	e[++cnt].nxt=head[u];
	e[cnt].to=v;
	e[cnt].w=ww;
	head[u]=cnt;
}
void dfs(ll u){
	pd[u]=1;
	for(ll i=head[u];i;i=head[u]){
		head[u]=e[i].nxt;
		ll v=e[i].to;
		dfs(v);
		if(e[i].w) ans.push_back(e[i].w);
	}
}
int main(){
	n=read();
	m=read();
	fr(i,1,n){
		fr(j,1,m){
			a[j]=read();
			if(ck[a[j]]) add(i,n+a[j],(i-1)*m+j);
			ck[a[j]]=1;
		}
		fr(j,1,m){
			if(!ck[j]) add(n+j,i,0);
			ck[j]=0;
		}
	}
	ans.push_back(n*m+1);
	fr(i,1,n){
		if(head[i]){
			while(pd[i]);
			dfs(i);
			ans.push_back(n*m+1);
		}
	}
	writeln((ll)ans.size()-1);
	fr(i,1,(ll)ans.size()-1) pf("%lld %lld\n",ans[i],ans[i-1]);
}

详细

Test #1:

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

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

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

result:

ok both subtasks are correct!

Test #3:

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

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

result:

ok both subtasks are correct!

Test #4:

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

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

result:

ok both subtasks are correct!

Test #5:

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

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
12213 13073
10354 12213
7854 10354
459 7854
3259 459
1459 3259
5159 1459
1862 5159
3158 1862
1858 3158
3192 1858
1892 3192
7562 1892
8849 7562
475 8849
1541 475
17469 1541
1569 17469
4941 1569
16555 4941
6955 16555
17855 6955
4955 17855
15140 4955
11540 15140
10355 11540
11555 10355
...

result:

ok both subtasks are correct!

Test #6:

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

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
47 4021
28 47
64 28
29 64
4 29
84 4
33 84
164 33
88 164
51 88
344 51
34 344
168 34
36 168
92 36
53 92
206 53
104 206
70 104
37 70
231 37
11 231
262 11
74 262
126 74
106 126
76 106
210 76
245 210
38 245
303 38
290 303
252 290
93 252
144 93
384 144
369 384
306 369
446 306
326 446
107 326
525 107
...

result:

ok both subtasks are correct!

Test #7:

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

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

result:

ok both subtasks are correct!

Test #8:

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

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
322 12041
42 322
362 42
82 362
402 82
122 402
442 122
162 442
482 162
202 482
522 202
242 522
562 242
2 562
642 2
602 642
43 602
643 43
83 643
682 83
123 682
722 123
163 722
762 163
203 762
802 203
243 802
842 243
282 842
683 282
323 683
723 323
363 723
763 363
403 763
803 403
443 803
843 443
...

result:

ok both subtasks are correct!

Test #9:

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

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
512 40001
113 512
7 113
206 7
22 206
210 22
118 210
319 118
24 319
1005 24
215 1005
713 215
31 713
125 31
418 125
613 418
218 613
128 218
715 128
32 715
513 32
329 513
129 329
33 129
917 33
130 917
34 130
133 34
219 133
40 219
520 40
230 520
136 230
330 136
720 330
627 720
138 627
920 138
239 ...

result:

ok both subtasks are correct!

Test #10:

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

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
338 6401
1936 338
977 1936
806 977
182 806
1328 182
2105 1328
17 2105
831 17
666 831
189 666
504 189
1174 504
28 1174
192 28
40 192
353 40
1470 353
45 1470
2417 45
195 2417
839 195
705 839
52 705
1178 52
714 1178
56 714
366 56
1803 366
205 1803
1340 205
226 1340
841 226
229 841
1631 229
58 1631...

result:

ok both subtasks are correct!

Test #11:

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

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
119 40001
1115 119
9 1115
132 9
12 132
311 12
16 311
207 16
18 207
134 18
20 134
507 20
317 507
24 317
820 24
138 820
329 138
709 329
140 709
25 140
331 25
30 331
603 30
419 603
36 419
141 36
339 141
1314 339
727 1314
430 727
37 430
905 37
340 905
45 340
1421 45
341 1421
208 341
347 208
147 34...

result:

ok both subtasks are correct!

Test #12:

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

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
322 6021
23 322
343 23
42 343
362 42
63 362
383 63
82 383
402 82
123 402
423 123
143 423
445 143
162 445
482 162
203 482
502 203
3 502
522 3
242 522
544 242
262 544
602 262
4 602
622 4
25 622
642 25
44 642
665 44
64 665
723 64
84 723
742 84
102 742
763 102
124 763
784 124
144 784
802 144
5 802
...

result:

ok both subtasks are correct!

Test #13:

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

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
631 90001
15 631
309 15
1213 309
312 1213
40 312
916 40
49 916
945 49
1813 945
962 1813
53 962
332 53
55 332
2726 55
637 2726
335 637
644 335
350 644
648 350
2730 648
354 2730
660 354
360 660
1521 360
1816 1521
361 1816
57 361
966 57
68 966
363 68
2148 363
1217 2148
970 1217
366 970
69 366
123...

result:

ok both subtasks are correct!

Test #14:

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

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
802 2
3 802
1602 3
1203 1602
4 1203
2002 4
1204 2002
803 1204
405 803
1603 405
804 1603
1604 804
5 1604
2402 5
1205 2402
406 1205
2003 406
7 2003
809 7
2004 809
1605 2004
408 1605
2404 408
8 2404
3202 8
1206 3202
2005 1206
409 2005
810 409
2802 810
9 2802
1208 9
811 1208
2405 8...

result:

ok both subtasks are correct!

Test #15:

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

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

result:

ok both subtasks are correct!

Test #16:

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

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
1228 60201
220 1228
621 220
13 621
221 13
1234 221
2808 1234
16 2808
231 16
3208 231
232 3208
4812 232
25 4812
627 25
405 627
244 405
29 244
630 29
416 630
824 416
417 824
633 417
1246 633
637 1246
5235 637
246 5235
1011 246
1247 1011
419 1247
250 419
830 250
438 830
252 438
6224 252
253 6224
...

result:

ok both subtasks are correct!

Test #17:

score: 5
Accepted
time: 15ms
memory: 11544kb

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
802 80401
2 802
1202 2
803 1202
402 803
1203 402
3 1203
1604 3
804 1604
404 804
1605 404
4 1605
2002 4
5 2002
2402 5
6 2402
2802 6
7 2802
3202 7
8 3202
3602 8
9 3602
4002 9
10 4002
4402 10
11 4402
4802 11
12 4802
5202 12
13 5202
5602 13
15 5602
6003 15
16 6003
6402 16
17 6402
6802 17
18 6802
7...

result:

ok both subtasks are correct!

Test #18:

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

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
615 120001
1552 615
1216 1552
617 1216
1241 617
26 1241
323 26
28 323
3616 28
43 3616
325 43
48 325
337 48
1554 337
53 1554
5138 53
645 5138
1555 645
1248 1555
351 1248
1253 351
354 1253
1259 354
924 1259
65 924
2444 65
1269 2444
372 1269
66 372
1556 66
647 1556
75 647
649 75
1823 649
1561 182...

result:

ok both subtasks are correct!

Test #19:

score: 0
Wrong Answer
time: 8ms
memory: 9520kb

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:

128080
132548 132868
132547 132548
132546 132547
132545 132546
132544 132545
132542 132544
132541 132542
132540 132541
132539 132540
132538 132539
132536 132538
132470 132536
132471 132470
132472 132471
132473 132472
132475 132473
132476 132475
132477 132476
132478 132477
132479 132478
132481 132479...

result:

wrong answer first subtask is incorrect

Test #20:

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

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
430 160001
2828 430
26 2828
433 26
35 433
856 35
37 856
461 37
1228 461
2033 1228
41 2033
464 41
47 464
1247 47
4837 1247
61 4837
468 61
1630 468
863 1630
67 863
2428 67
867 2428
2064 867
874 2064
1634 874
2831 1634
470 2831
878 470
83 878
1255 83
2434 1255
1651 2434
485 1651
87 485
492 87
89 ...

result:

ok both subtasks are correct!