QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#371626#5137. TowerDjangle162857WA 1125ms19936kbC++141.8kb2024-03-30 14:32:252024-03-30 14:34:20

Judging History

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

  • [2024-03-30 14:34:20]
  • 评测
  • 测评结果:WA
  • 用时:1125ms
  • 内存:19936kb
  • [2024-03-30 14:32:25]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " == " << x << endl
#define el '\n'
#define fir first
#define sec second
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1000000007;
const int inf = 0x3f3f3f3f;
const int N = 200020;
inline int getans(int x, int y)
{
	if (x <= y)
		return y - x;
	int tmp = 0;
	while (x >= y * 2) {
		tmp++;
		x = x / 2;
	}
	return min(y - (x / 2) + 1, x - y) + tmp;
}
int a[550], res[550];
void solve()
{
	int n, m, mn = inf;
	scanf("%d%d", &n, &m);
	if (n == m) {
		printf("0\n");
		return;
	}
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		mn = min(mn, a[i]);
	}
	ll ans = inf;
	map<int, int> mp;
	vector<int> q;
	for (int x = 1; x <= n; x++) {
		q.push_back(a[x]);
		int L = max(a[x] - 29, 1), R = a[x] + 29;
		for (int i = L; i <= R; i++) {
			if (mp.find(i) == mp.end()) {
				mp[i] = 1;
			}
			else {
				if (mp[i] == n - m)
					q.push_back(i);
				mp[i]++;
			}
		}
		int rr = a[x];
		int tmp = 1;
		while (rr >= 1) {
			rr = rr / 2;
			L = max(rr - 29 + tmp, 1), R = rr + 29 - tmp;
			for (int i = L; i <= R; i++) {
				if (mp.find(i) == mp.end()) {
					mp[i] = 1;
				}
				else {
					if (mp[i] == n - m)
						q.push_back(i);
					mp[i]++;
				}
			}
			tmp++;
		}
	}
	for (int i : q) {
		// debug(i);
		for (int j = 1; j <= n; j++) {
			int now = getans(a[j], i);
			// cout << now << " ";
			res[j] = now;
		}
		// cout << endl;
		sort(res + 1, res + n + 1);
		ll sum = 0;
		for (int j = 1; j <= n - m; j++) {
			sum += res[j];
		}
		ans = min(ans, sum);
	}
	printf("%lld\n", ans);
}
signed main()
{
	/*ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);*/
	int T = 1;
	cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3784kb

input:

3
2 0
2 6
5 0
1 2 3 4 5
5 3
1 2 3 4 5

output:

2
4
1

result:

ok 3 number(s): "2 4 1"

Test #2:

score: 0
Accepted
time: 30ms
memory: 3780kb

input:

10
272 118
11 14 49 94 71 62 46 45 74 22 15 36 7 37 27 35 96 85 75 78 76 64 23 59 17 35 71 28 96 82 5 66 2 48 57 31 88 10 61 73 79 23 19 52 39 76 48 98 5 39 48 51 90 90 60 27 47 24 24 56 48 27 39 21 38 18 20 9 62 83 47 15 51 22 73 74 7 80 64 60 86 74 59 7 84 38 99 31 42 60 52 41 63 88 59 90 77 40 68...

output:

454
3
436
108
570
636
994
227
656
50

result:

ok 10 numbers

Test #3:

score: 0
Accepted
time: 26ms
memory: 3824kb

input:

10
133 89
20 70 6 45 4 72 38 7 18 1 82 39 69 85 5 36 1 62 30 47 68 55 7 41 7 42 7 61 11 82 2 80 80 93 29 30 42 58 73 26 99 67 60 94 61 46 47 54 44 50 35 88 61 17 23 97 90 28 16 47 75 35 28 14 42 63 26 40 95 58 26 25 26 83 93 56 17 27 7 90 91 28 53 49 47 84 55 52 11 34 14 74 40 65 84 32 99 46 1 21 31...

output:

88
1361
128
246
29
83
3
677
96
382

result:

ok 10 numbers

Test #4:

score: 0
Accepted
time: 100ms
memory: 3808kb

input:

10
500 50
67 93 11 58 54 40 37 3 92 96 91 20 46 5 21 43 3 2 7 47 27 81 14 53 86 21 46 51 86 22 42 14 52 38 42 25 34 29 84 42 43 96 11 100 27 60 48 15 13 69 58 16 14 58 17 94 8 71 39 38 25 37 100 58 99 56 65 84 94 63 25 34 13 73 83 83 69 60 70 15 15 90 7 11 88 69 13 26 99 28 16 97 32 40 76 62 41 5 9 ...

output:

1608
169
144
983
1087
1317
882
75
32
1259

result:

ok 10 numbers

Test #5:

score: 0
Accepted
time: 218ms
memory: 4132kb

input:

10
500 414
503 505 103 380 946 153 952 386 890 306 522 147 499 784 643 121 264 344 549 72 299 314 45 688 97 747 442 528 752 830 335 78 159 218 748 331 259 375 479 883 202 402 595 738 430 184 874 762 864 743 733 209 821 616 868 543 314 161 100 638 439 943 732 962 243 776 803 423 749 367 731 594 993 9...

output:

338
2653
2857
809
1626
332
1328
490
1044
854

result:

ok 10 numbers

Test #6:

score: 0
Accepted
time: 447ms
memory: 4344kb

input:

10
500 497
4249 4173 5055 5942 4090 1754 1523 5273 758 3522 8827 3775 6331 2729 8699 8797 5977 5435 6320 9188 5889 6562 9809 7595 6104 7480 2116 8715 2823 1990 425 5811 3347 2618 6119 3948 7172 7095 8017 5943 2036 87 6661 2099 885 3035 3745 8362 3919 2675 1314 8123 7254 328 106 2546 7540 9303 4333 9...

output:

1
2260
3254
4965
2322
2422
4862
1174
3671
877

result:

ok 10 numbers

Test #7:

score: 0
Accepted
time: 541ms
memory: 6472kb

input:

10
500 425
62346 35359 49386 37821 13178 34961 89198 87150 5961 67958 2778 83160 89447 17663 63690 96481 48566 27701 64933 35987 44454 52207 22761 72984 57775 88898 28120 4798 93898 2808 185 49754 67340 4153 38477 14377 97568 57830 78927 11857 44320 71781 62631 7685 42960 80182 69195 31752 95159 311...

output:

762
548
2235
505
1333
5729
5820
3724
4260
2803

result:

ok 10 numbers

Test #8:

score: 0
Accepted
time: 1125ms
memory: 13700kb

input:

10
500 343
3979933 4977754 3585357 8727522 1167921 850266 4372205 6136332 1208124 9005074 1888230 1818841 5532232 8097244 9323282 2862526 1081283 5639323 3113788 3478923 6969022 3572708 8591079 9223149 25281 7629530 7701175 2406412 8085960 4273048 6252416 7216852 310879 1781062 1016170 6154578 21346...

output:

2803
0
1172
7122
9860
7880
7326
5368
1348
1133

result:

ok 10 numbers

Test #9:

score: 0
Accepted
time: 798ms
memory: 16752kb

input:

10
500 337
8020609 91599948 284472 11014859 43731772 94734724 12907680 35883604 79976518 69620407 40667149 80019777 13205478 88987382 56851734 57312628 86016653 88153839 57436370 11777363 52281260 97911489 94737731 32588013 32104751 52267758 97646175 98939956 72977817 75964526 12807784 72438205 6797...

output:

3472
4278
5012
368
11069
4964
2159
9322
7802
7665

result:

ok 10 numbers

Test #10:

score: 0
Accepted
time: 832ms
memory: 19640kb

input:

10
500 399
42649299 961565652 731155387 495426036 927067195 429839645 335971489 846530637 913519418 120090307 242077430 62797226 117328086 261085207 332119648 917622458 982277579 237456542 108626001 724449186 247397791 193474848 886441482 245912131 547396118 454298309 959881298 690112275 996868401 4...

output:

2404
3054
10040
11934
7799
2380
10134
11780
8824
9196

result:

ok 10 numbers

Test #11:

score: 0
Accepted
time: 98ms
memory: 4088kb

input:

10
500 250
43 6 41 44 86 71 16 48 41 58 88 64 24 89 50 62 89 42 11 26 66 5 66 86 91 63 7 17 50 44 94 38 25 60 89 82 25 10 72 96 53 61 11 18 7 77 95 69 89 86 43 68 61 41 67 30 86 72 90 34 73 94 100 93 19 40 46 47 86 83 42 22 12 73 60 12 88 35 99 7 7 28 55 80 15 75 27 22 32 26 14 65 93 81 3 83 2 71 21...

output:

688
712
689
666
686
674
694
710
708
692

result:

ok 10 numbers

Test #12:

score: 0
Accepted
time: 93ms
memory: 3828kb

input:

10
500 250
47 10 93 78 96 63 78 93 72 25 92 78 72 68 51 15 66 48 33 66 56 90 47 76 98 51 40 32 50 89 8 16 70 80 88 88 25 22 25 64 98 2 54 40 78 76 3 8 52 74 32 87 88 3 36 73 90 64 80 61 82 36 93 96 12 94 77 32 9 14 52 49 73 93 91 73 36 78 30 65 61 21 48 43 13 31 48 43 53 89 47 91 71 6 45 54 8 56 37 ...

output:

719
701
717
703
722
706
689
676
711
689

result:

ok 10 numbers

Test #13:

score: 0
Accepted
time: 206ms
memory: 3832kb

input:

10
500 250
610 503 971 141 889 684 508 173 619 687 92 674 169 198 579 266 866 694 803 158 835 565 76 490 252 615 884 641 983 37 104 990 5 61 364 949 719 906 155 935 142 259 380 324 487 274 545 11 975 227 773 157 46 652 73 664 51 723 283 743 148 594 739 887 856 312 291 380 492 538 139 770 174 911 582...

output:

1392
1314
1414
1398
1432
1397
1408
1379
1413
1410

result:

ok 10 numbers

Test #14:

score: 0
Accepted
time: 372ms
memory: 4216kb

input:

10
500 250
3146 8715 6563 563 5680 5446 6622 7756 7069 1897 675 3201 3122 4477 5001 5092 6227 9436 3045 3083 1807 5651 4655 4373 9114 6241 7680 4219 6649 1746 645 4353 2713 9141 3171 8507 5596 5304 8551 3276 4001 7365 7464 6410 6943 4246 2172 4958 3725 2949 6099 2151 9953 1710 3124 5614 1956 5013 25...

output:

2233
2145
2211
2223
2181
2171
2160
2147
2196
2216

result:

ok 10 numbers

Test #15:

score: 0
Accepted
time: 857ms
memory: 19656kb

input:

10
500 250
85414674 700629986 208785215 725368875 657246004 592413273 991859438 869099417 518807579 871532580 761787849 59907939 222859513 782592722 361466960 834516007 326719123 104949098 150164624 861615809 983355489 967603809 310462874 762243476 74461252 243437298 443230947 187927955 203499298 20...

output:

6310
6316
6317
6345
6365
6352
6366
6324
6355
6351

result:

ok 10 numbers

Test #16:

score: 0
Accepted
time: 866ms
memory: 19628kb

input:

10
500 250
94363318 32525117 946318983 582157079 187761218 675201416 591023719 628529432 288745868 796609835 771030418 476414479 179041904 921000086 234820104 219863550 960291562 396714559 944517580 339032476 359404425 496787354 494491203 284714887 15884218 206509548 350824351 694445152 617080395 34...

output:

6355
6333
6342
6397
6333
6294
6377
6366
6322
6369

result:

ok 10 numbers

Test #17:

score: 0
Accepted
time: 854ms
memory: 19724kb

input:

10
500 250
103311963 511903897 683852750 291461634 718276431 341015321 358543394 165464372 590767638 582787245 574203441 632789340 892921020 135224295 875766971 687047485 225743788 938583469 466709995 636602413 558528691 568644225 749309612 721305563 798259269 627187449 145453006 643446194 502803179...

output:

6368
6331
6385
6341
6374
6373
6353
6374
6348
6332

result:

ok 10 numbers

Test #18:

score: 0
Accepted
time: 828ms
memory: 19620kb

input:

10
500 250
112260608 843799028 421386517 148249838 248791645 789058169 41885373 887388673 700489491 876828621 499280696 642031909 309427561 91406685 683050208 84140378 536705431 476170894 925508553 777884025 619646796 369278984 66420690 426726908 242525341 903550548 596460860 817295642 660240790 389...

output:

6319
6343
6366
6339
6344
6374
6318
6323
6335
6353

result:

ok 10 numbers

Test #19:

score: 0
Accepted
time: 845ms
memory: 19936kb

input:

10
500 250
121209252 175694159 158920284 926790506 237101016 872710999 609312974 662727697 170869998 276874302 503790831 725934102 47589076 637817092 444018599 90020616 42650932 606700866 168255727 145004768 987123826 254818341 880414698 383531768 132148253 686791413 179913647 843661442 817678402 69...

output:

6381
6305
6352
6382
6371
6339
6351
6324
6393
6347

result:

ok 10 numbers

Test #20:

score: 0
Accepted
time: 851ms
memory: 19580kb

input:

10
500 250
156876400 42649299 961565652 731155387 495426036 927067195 429839645 335971489 846530637 913519418 120090307 242077430 62797226 117328086 261085207 332119648 917622458 982277579 237456542 108626001 724449186 247397791 193474848 886441482 245912131 547396118 454298309 959881298 690112275 9...

output:

6339
6371
6322
6346
6339
6371
6317
6343
6379
6355

result:

ok 10 numbers

Test #21:

score: 0
Accepted
time: 24ms
memory: 3776kb

input:

10
272 118
63 29 32 72 70 84 31 34 75 75 52 61 76 80 63 100 23 71 62 78 42 87 74 77 60 88 18 56 35 65 15 81 40 33 47 54 66 44 73 99 19 80 63 68 68 74 71 19 19 38 82 78 88 31 34 46 98 16 75 18 26 51 39 86 18 81 17 51 3 68 38 64 20 60 16 85 95 76 68 71 76 97 71 99 19 67 21 13 74 72 7 22 73 30 81 68 30...

output:

410
647
52
427
361
220
371
44
222
36

result:

ok 10 numbers

Test #22:

score: 0
Accepted
time: 88ms
memory: 3788kb

input:

10
500 346
96 36 82 50 99 51 20 51 86 100 53 91 95 89 51 45 59 60 66 49 70 61 34 66 50 100 11 10 100 71 50 4 98 3 76 95 29 98 98 74 31 52 42 87 29 52 27 53 49 15 98 100 52 28 29 97 99 50 49 52 20 26 7 48 37 55 54 39 20 51 50 100 15 36 54 49 48 53 80 58 99 74 96 17 11 98 100 96 100 49 96 19 81 17 50 ...

output:

197
933
785
415
595
189
712
433
62
1179

result:

ok 10 numbers

Test #23:

score: 0
Accepted
time: 211ms
memory: 3884kb

input:

10
500 109
987 996 995 924 999 93 995 990 994 996 998 993 995 955 919 993 1000 47 458 990 996 997 984 999 748 992 275 994 993 995 997 989 993 1000 995 35 993 995 995 997 995 999 994 468 999 998 989 1000 995 994 1000 995 989 989 988 993 993 469 991 874 990 96 994 986 420 995 999 997 991 381 996 996 1...

output:

956
740
199
339
282
640
578
382
1197
424

result:

ok 10 numbers

Test #24:

score: -100
Wrong Answer
time: 354ms
memory: 4500kb

input:

10
500 145
1856 3718 3716 1859 1842 1830 9351 4464 462 3338 3967 3718 7427 1775 3622 1858 466 3713 67 464 470 938 4499 929 1852 469 1852 8329 8816 3680 9291 233 3712 934 464 926 1847 466 7426 464 540 1857 926 3712 466 8655 3696 7424 1852 927 2014 5077 7413 3702 1856 1589 1869 915 3694 7420 2787 232 ...

output:

1307
295
280
482
732
1539
974
493
1558
987

result:

wrong answer 6th numbers differ - expected: '1527', found: '1539'