QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#93815#5690. 背包chenshiWA 84ms5604kbC++781b2023-04-02 22:54:352023-04-02 22:54:38

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-02 22:54:38]
  • 评测
  • 测评结果:WA
  • 用时:84ms
  • 内存:5604kb
  • [2023-04-02 22:54:35]
  • 提交

answer

#include<cstdio>
#include<queue>
#include<utility>
using namespace std;
const int o=1e5+10;const long long inf=2e18;
int n,q,v[o],c[o],p=1;long long f[o],V;bool vis[o];priority_queue<pair<long long,int> > Q;
int main(){
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;++i){
		scanf("%d%d",&v[i],&c[i]);
		if(c[i]*1ll*v[p]>c[p]*1ll*v[i]) p=i;
	}
	for(int i=0;i<v[p];++i) f[i]=-inf;
	for(Q.push(make_pair(f[0]=0,0));!Q.empty();){
		int t=Q.top().second;
		Q.pop();
		if(vis[t]) continue;
		vis[t]=1;
		for(int i=1;i<=n;++i) if(f[(t+v[i])%v[p]]<f[t]+c[i]-(t+v[i])/v[p]*1ll*c[p])
			Q.push(make_pair(f[(t+v[i])%v[p]]=f[t]+c[i]-(t+v[i])/v[p]*1ll*c[p],(t+v[i])%v[p]));
	}
	for(;q--;printf("%lld\n",(f[V%v[p]]>-inf)?V/v[p]*c[p]+f[V%v[p]]:-1)) scanf("%lld",&V);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 35ms
memory: 3112kb

input:

50 100000
51305 277520
85830 111973
14837 979296
64100 235055
72474 557263
36773 232129
62774 398759
70740 834677
25120 999531
81191 28056
90133 884467
16462 693203
27057 616092
34713 932782
89420 663734
16437 298828
91123 516501
24430 267003
85485 535000
54839 145786
28114 187135
43791 474768
71273...

output:

811136115447000000
130312175752000000
831238227959000000
711780431949000000
567014385469000000
176643060888000000
532602712803000000
228620751332000000
434289249665000000
964750609099000000
271686175594000000
300113128686000000
853267533241000000
291269801555000000
450299770506000000
440721497066000...

result:

ok 100000 lines

Test #2:

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

input:

50 100000
97830 451823
37513 797833
61527 952574
98951 460952
9982 483106
39784 511945
98493 933482
90672 304557
73232 677587
81302 710167
50101 771645
1815 118770
32519 644183
79650 108103
13496 441661
46853 653992
17707 729081
40996 885010
30757 661427
36297 776622
63656 551419
58205 301706
50404 ...

output:

87402683733488322
48821086339507431
54200141913056370
27277013968053122
47783263639132800
39456586132249193
80866789029835593
63984560456175570
47041442747001970
31332172417359200
89341569089851001
43185914896957361
66381017294811522
71170240573169731
47735901033133922
27793564332294224
352626562721...

result:

ok 100000 lines

Test #3:

score: 0
Accepted
time: 12ms
memory: 3084kb

input:

50 100000
57263 689683
56297 264033
6254 774315
33923 212780
6212 547205
8250 668658
86884 679323
90655 998890
96634 362315
95661 541177
40681 728365
29251 318945
67206 418049
2303 471641
95083 531168
30415 507838
70429 863453
5068 974889
6841 89223
8041 645338
12274 135629
86594 169052
89426 798614...

output:

833769177988112
572090677551067
464406011426906
818311238036803
1003262593101894
1336412154649384
329762174052437
1424282613223876
283137801198865
513200208898777
1637543755241494
1500903213554974
759864122863173
1502802350468135
1231863031805930
446937204873378
830422276738924
896894387150280
19729...

result:

ok 100000 lines

Test #4:

score: 0
Accepted
time: 18ms
memory: 3124kb

input:

50 100000
18494 783117
27871 880374
9240 141155
88777 868504
31614 469656
54682 266336
73903 264144
69799 764433
37030 416907
24229 258867
31288 431580
38125 734733
38359 595082
21011 607598
76570 34351
18676 184727
34232 531927
45785 992426
85481 111898
33486 623833
29692 307948
16666 556170
50935 ...

output:

38623810694148
144946763634542
97231099112179
257850888125523
331524785992064
278600160971218
164361098471092
177155124854192
117032152448146
335939676920670
103210585498030
98309090219728
294994806569001
104987065617304
341219250633459
90013959444023
49269785767936
165310341961290
61142143266693
33...

result:

ok 100000 lines

Test #5:

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

input:

50 100000
78683 523491
13081 779961
75556 285324
19204 292954
73701 613598
13373 129108
67492 362483
24218 586632
14574 485692
21680 397143
59383 168482
94217 307620
84352 772543
22924 350057
36242 688838
96664 521058
27243 694241
39878 62956
42700 287856
45457 820528
18351 446340
69767 277466
83157...

output:

37519085868329
24507561853641
32108068555119
35735837863647
15271685639057
20478179070936
58611788877020
20559193767388
27659389424996
41178514258056
27665191814466
58034786533252
13005157817902
14903581256267
24490840413894
10692312977519
24287371542654
10027569734451
13833872243201
45946712205513
...

result:

ok 100000 lines

Test #6:

score: 0
Accepted
time: 28ms
memory: 4064kb

input:

50 100000
59960 29977
50680 25337
95900 47947
66600 33297
75060 37527
62620 31307
98040 49017
90280 45137
89420 44707
13580 6787
49780 24887
79020 39507
26920 13457
44360 22177
19980 9987
58600 29297
63120 31557
59420 29707
60080 30037
83420 41707
69500 34747
99480 49737
8400 4197
35840 17917
59840 ...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
294458059041
-1
-1
-1
94822437539
-1
-1
56956583622
-1
-1
-1
445752203772
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
178183763370
-1
107588338242
-1
226639511793
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
146566707165
-1
...

result:

ok 100000 lines

Test #7:

score: 0
Accepted
time: 84ms
memory: 5604kb

input:

50 100000
65412 327057
63744 318717
16672 83357
32276 161377
75002 375007
6474 32367
27520 137597
87848 439237
50404 252017
26986 134927
43592 217957
34920 174597
71640 358197
5436 27177
5886 29427
92138 460687
41700 208497
10528 52637
14048 70237
13902 69507
6912 34557
45396 226977
8594 42967
49000...

output:

1028953550537
-1
-1
922669181041
-1
-1
2636203394334
2263351470911
-1
4999011409557
-1
-1
3273633920658
-1
-1
4763039198381
-1
2146320253739
-1
4645553652747
2888839997901
1076872157219
1638093628668
-1
-1
-1
1612024665879
-1
1693113525378
4317338970865
968954545361
4830713234037
4451577884611
15724...

result:

ok 100000 lines

Test #8:

score: -100
Wrong Answer
time: 61ms
memory: 4904kb

input:

50 100000
11359 24827
14238 30180
26261 53976
52183 115398
35531 79368
97907 215047
22935 47611
81831 177954
37064 80132
33428 72334
18280 36349
168 130
68424 150795
28551 62665
92840 204792
95822 211944
835 8
78731 175689
40943 87938
70956 158108
53418 118280
13906 26879
53232 114131
81318 178470
5...

output:

627651580645
1213117947385
1814092905034
1992894295076
1576264147838
844326514231
1285347012662
688129587313
435210130372
834708859948
989682275846
713734009044
1179772029947
2093982852711
435727387709
939689700162
501700821843
942677662444
1061983715595
1891827920610
2203269714021
482151018961
1343...

result:

wrong answer 1st lines differ - expected: '627651581043', found: '627651580645'