QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#408543#8425. KnapsackieeAC ✓1543ms81780kbC++17707b2024-05-10 17:03:042024-05-10 17:03:50

Judging History

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

  • [2024-05-10 17:03:50]
  • 评测
  • 测评结果:AC
  • 用时:1543ms
  • 内存:81780kb
  • [2024-05-10 17:03:04]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
constexpr int lim = 1e7;
int n, W, B, a[65], s[65], p;
int f[lim], res;
void dfs(int u, int cur) {
	if (cur < 0 || cur > s[u]) return;
	if (u == p) {
		res += f[cur];
		return;
	}
	for (int j : {0ll, a[u], a[u] * 2}) {
		dfs(u - 1, cur - j);
	}
}
signed main() {
	cin >> n >> W;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		s[i] = s[i - 1] + a[i] * 2;
	}
	while (p < n && s[p + 1] < lim) p++;
	f[0] = 1;
	for (int i = 1; i <= p; i++) {
		for (int k = lim - 1; k >= a[i]; k--) {
			f[k] += f[k - a[i]];
			if (k >= a[i] * 2) f[k] += f[k - a[i] * 2];
		}
	}
	dfs(n, W);
	cout << res << "\n";
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 55ms
memory: 81664kb

input:

5 100
2 5 10 21 49

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 7ms
memory: 81756kb

input:

1 2
1

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 38ms
memory: 81624kb

input:

5 54
1 2 4 8 16

output:

4

result:

ok 1 number(s): "4"

Test #4:

score: 0
Accepted
time: 102ms
memory: 81776kb

input:

10 1596
1 2 4 8 16 32 64 128 256 512

output:

29

result:

ok 1 number(s): "29"

Test #5:

score: 0
Accepted
time: 234ms
memory: 81692kb

input:

20 1289435
1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288

output:

1991

result:

ok 1 number(s): "1991"

Test #6:

score: 0
Accepted
time: 255ms
memory: 81780kb

input:

30 782188728
1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912

output:

78959

result:

ok 1 number(s): "78959"

Test #7:

score: 0
Accepted
time: 251ms
memory: 81708kb

input:

40 361840927053
1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 8589934592 17179869184 34359738368 68719476736 137438953472 274877906944 5...

output:

3453581

result:

ok 1 number(s): "3453581"

Test #8:

score: 0
Accepted
time: 247ms
memory: 81700kb

input:

50 228667299193708
1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 8589934592 17179869184 34359738368 68719476736 137438953472 27487790694...

output:

41684563

result:

ok 1 number(s): "41684563"

Test #9:

score: 0
Accepted
time: 310ms
memory: 81700kb

input:

60 743520376398163711
1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 8589934592 17179869184 34359738368 68719476736 137438953472 27487790...

output:

696941793

result:

ok 1 number(s): "696941793"

Test #10:

score: 0
Accepted
time: 7ms
memory: 81772kb

input:

1 0
1

output:

1

result:

ok 1 number(s): "1"

Test #11:

score: 0
Accepted
time: 53ms
memory: 81620kb

input:

5 28
2 5 10 21 43

output:

1

result:

ok 1 number(s): "1"

Test #12:

score: 0
Accepted
time: 102ms
memory: 81612kb

input:

10 1493
1 3 8 17 36 72 145 291 582 1166

output:

30

result:

ok 1 number(s): "30"

Test #13:

score: 0
Accepted
time: 215ms
memory: 81628kb

input:

20 568052
1 4 9 20 40 80 160 322 645 1290 2581 5163 10328 20656 41314 82630 165262 330525 661052 1322106

output:

102

result:

ok 1 number(s): "102"

Test #14:

score: 0
Accepted
time: 222ms
memory: 81772kb

input:

30 1013865320
1 3 7 15 31 64 128 256 512 1025 2050 4101 8204 16408 32818 65638 131276 262553 525106 1050212 2100424 4200850 8401700 16803400 33606800 67213600 134427200 268854401 537708803 1075417608

output:

10333

result:

ok 1 number(s): "10333"

Test #15:

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

input:

40 4354009841348
1 4 8 16 32 66 134 269 538 1077 2156 4314 8630 17261 34522 69045 138092 276185 552371 1104744 2209488 4418978 8837958 17675917 35351836 70703673 141407346 282814692 565629386 1131258774 2262517548 4525035098 9050070196 18100140394 36200280790 72400561582 144801123164 289602246329 57...

output:

1228362

result:

ok 1 number(s): "1228362"

Test #16:

score: 0
Accepted
time: 216ms
memory: 81728kb

input:

50 4361674226510623
2 5 12 25 50 100 201 402 804 1610 3220 6440 12880 25761 51522 103044 206089 412179 824360 1648721 3297442 6594884 13189769 26379539 52759080 105518160 211036322 422072644 844145290 1688290581 3376581164 6753162328 13506324656 27012649313 54025298628 108050597257 216101194515 4322...

output:

76397319

result:

ok 1 number(s): "76397319"

Test #17:

score: 0
Accepted
time: 212ms
memory: 81628kb

input:

58 190465877692434859
2 6 14 28 56 112 226 453 907 1814 3629 7260 14520 29041 58082 116166 232332 464664 929330 1858660 3717322 7434644 14869289 29738578 59477156 118954312 237908624 475817249 951634500 1903269000 3806538000 7613076001 15226152003 30452304007 60904608015 121809216030 243618432062 48...

output:

127971909

result:

ok 1 number(s): "127971909"

Test #18:

score: 0
Accepted
time: 17ms
memory: 81756kb

input:

1 7
4

output:

0

result:

ok 1 number(s): "0"

Test #19:

score: 0
Accepted
time: 61ms
memory: 81712kb

input:

5 202
2 9 20 45 91

output:

2

result:

ok 1 number(s): "2"

Test #20:

score: 0
Accepted
time: 107ms
memory: 81716kb

input:

10 3419
1 2 8 17 36 76 156 315 633 1266

output:

18

result:

ok 1 number(s): "18"

Test #21:

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

input:

20 181855
1 6 12 26 52 104 210 425 852 1707 3414 6831 13667 27337 54674 109353 218706 437417 874837 1749677

output:

219

result:

ok 1 number(s): "219"

Test #22:

score: 0
Accepted
time: 229ms
memory: 81764kb

input:

30 3796823602
1 5 12 28 60 125 253 508 1020 2045 4092 8188 16378 32760 65521 131042 262088 524180 1048363 2096731 4193464 8386929 16773859 33547720 67095442 134190887 268381779 536763558 1073527118 2147054238

output:

48936

result:

ok 1 number(s): "48936"

Test #23:

score: 0
Accepted
time: 217ms
memory: 81680kb

input:

40 3389544476089
1 3 6 17 38 81 162 327 654 1310 2620 5242 10489 20983 41970 83944 167888 335776 671553 1343108 2686220 5372443 10744886 21489772 42979544 85959090 171918185 343836374 687672753 1375345506 2750691014 5501382030 11002764061 22005528122 44011056245 88022112492 176044224985 352088449975...

output:

608856

result:

ok 1 number(s): "608856"

Test #24:

score: 0
Accepted
time: 205ms
memory: 81708kb

input:

50 6873540501374253
5 10 20 41 87 174 352 709 1418 2839 5680 11363 22729 45460 90920 181845 363694 727391 1454783 2909570 5819143 11638289 23276579 46553161 93106325 186212653 372425310 744850623 1489701250 2979402500 5958805002 11917610008 23835220019 47670440043 95340880091 190681760187 3813635203...

output:

168426342

result:

ok 1 number(s): "168426342"

Test #25:

score: 0
Accepted
time: 216ms
memory: 81776kb

input:

58 2727595765455999772
4 9 21 45 91 184 369 742 1489 2979 5961 11926 23852 47707 95415 190835 381670 763343 1526687 3053375 6106750 12213500 24427002 48854004 97708012 195416024 390832048 781664101 1563328202 3126656407 6253312816 12506625633 25013251267 50026502539 100053005082 200106010169 4002120...

output:

76568784

result:

ok 1 number(s): "76568784"

Test #26:

score: 0
Accepted
time: 17ms
memory: 81716kb

input:

1 11
11

output:

1

result:

ok 1 number(s): "1"

Test #27:

score: 0
Accepted
time: 49ms
memory: 81668kb

input:

5 357
13 26 54 122 259

output:

0

result:

ok 1 number(s): "0"

Test #28:

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

input:

10 20973
3 15 38 83 174 362 727 1454 2914 5828

output:

2

result:

ok 1 number(s): "2"

Test #29:

score: 0
Accepted
time: 196ms
memory: 81768kb

input:

20 20598350
7 25 57 119 251 513 1039 2088 4185 8376 16753 33518 67045 134100 268214 536442 1072895 2145803 4291614 8583233

output:

226

result:

ok 1 number(s): "226"

Test #30:

score: 0
Accepted
time: 201ms
memory: 81728kb

input:

30 8452106455
5 23 53 110 222 452 912 1828 3668 7348 14698 29409 58824 117657 235326 470653 941313 1882630 3765275 7530558 15061129 30122264 60244537 120489086 240978178 481956369 963912750 1927825512 3855651031 7711302072

output:

4349

result:

ok 1 number(s): "4349"

Test #31:

score: 0
Accepted
time: 190ms
memory: 81724kb

input:

40 9777057269708
8 31 68 138 283 571 1145 2305 4625 9252 18508 37030 74063 148133 296275 592555 1185114 2370239 4740483 9480976 18961959 37923925 75847865 151695741 303391486 606782983 1213565968 2427131944 4854263898 9708527803 19417055618 38834111240 77668222489 155336444980 310672889962 621345779...

output:

59532

result:

ok 1 number(s): "59532"

Test #32:

score: 0
Accepted
time: 210ms
memory: 81656kb

input:

50 16435327948960443
5 11 27 55 121 244 502 1013 2028 4064 8134 16283 32567 65139 130285 260578 521157 1042316 2084644 4169301 8338602 16677212 33354429 66708869 133417740 266835488 533670983 1067341969 2134683950 4269367904 8538735818 17077471646 34154943301 68309886605 136619773219 273239546448 54...

output:

31482368

result:

ok 1 number(s): "31482368"

Test #33:

score: 0
Accepted
time: 246ms
memory: 81664kb

input:

57 1321475674704693207
3 9 22 59 118 251 510 1023 2051 4116 8240 16480 32974 65952 131908 263827 527667 1055343 2110688 4221391 8442792 16885593 33771197 67542404 135084809 270169623 540339259 1080678532 2161357079 4322714158 8645428323 17290856647 34581713302 69163426607 138326853214 276653706441 5...

output:

827076934

result:

ok 1 number(s): "827076934"

Test #34:

score: 0
Accepted
time: 379ms
memory: 81680kb

input:

59 1240296099405754799
1 3 7 16 34 70 141 282 564 1129 2259 4518 9036 18074 36148 72296 144594 289188 578378 1156757 2313516 4627033 9254067 18508136 37016273 74032547 148065095 296130192 592260386 1184520774 2369041550 4738083101 9476166203 18952332407 37904664815 75809329632 151618659265 303237318...

output:

13967413787

result:

ok 1 number(s): "13967413787"

Test #35:

score: 0
Accepted
time: 1543ms
memory: 81704kb

input:

60 768614336404564650
1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 8589934592 17179869184 34359738368 68719476736 137438953472 27487790...

output:

2504730781961

result:

ok 1 number(s): "2504730781961"

Test #36:

score: 0
Accepted
time: 138ms
memory: 81708kb

input:

44 782231275173653669
1 75024 165155 407040 864834 1788907 3668008 7371433 14795293 29637061 59291972 118621021 237331896 474717023 949461871 1898958266 3797969315 7595985441 15192048828 30384133427 60768307243 121536615452 243073274824 486146584665 972293260126 1944586528702 3889173080572 777834616...

output:

239

result:

ok 1 number(s): "239"