QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#85904#5453. Mana CollectionAppleblue178.333333 761ms112008kbC++142.6kb2023-03-08 21:02:512023-03-08 21:02:51

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-08 21:02:51]
  • 评测
  • 测评结果:8.333333
  • 用时:761ms
  • 内存:112008kb
  • [2023-03-08 21:02:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const long long N=22,M=3e5+5,INF=1e18;
long long n,m,q;
long long a[N],G[N][N];
long long K[M],dp[M][N];
long long X[M],U[M];
long long v[M],vid;

class segtree{
	public:
		struct seg{
			long long k,b;
		}P[M];
		long long id;
		double cal(long long pos,long long x){
			return v[pos]*P[x].k+P[x].b;
		}
		long long f[M*4];
		void modify(long long l,long long r,long long o,long long L,long long R,long long x){
			long long mid=(l+r)>>1;
			if(L<=l && r<=R){
				if(l==r){
					if(cal(l,x)>cal(l,f[o])) f[o]=x;
					return ;
				}
				if(cal(mid,x)>cal(mid,f[o])) swap(f[o],x);
				if(cal(l,x)>cal(l,f[o])) modify(l,mid,o<<1,L,R,x);
				else if(cal(r,x)>cal(r,f[o])) modify(mid+1,r,o<<1|1,L,R,x);
				return ;
			}
			if(L<=mid) modify(l,mid,o<<1,L,R,x);
			if(R>mid) modify(mid+1,r,o<<1|1,L,R,x);
		}
		long long query(long long l,long long r,long long o,long long pos){
			if(l==r) return cal(pos,f[o]);
			long long mid=(l+r)>>1;
			long long tot=cal(pos,f[o]);
			if(pos<=mid) tot=max(tot,query(l,mid,o<<1,pos));
			else tot=max(tot,query(mid+1,r,o<<1|1,pos));
			return tot;
		}
}F[N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	for(long long i=0;i<n;i++) cin>>a[i];
	
	for(long long i=0;i<n;i++)
		for(long long j=0;j<n;j++)
			if(i!=j) G[i][j]=INF;
	for(long long i=1;i<=m;i++){
		long long u,v,w; cin>>u>>v>>w; u--,v--;
		G[u][v]=w;
	}
	for(long long k=0;k<n;k++)
		for(long long i=0;i<n;i++)
			for(long long j=0;j<n;j++)
				G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
	
	for(long long mac=0;mac<(1<<n);mac++){
		for(long long i=0;i<n;i++)
			if(mac>>i & 1) K[mac]+=a[i];
	}
	for(long long mac=0;mac<(1<<n);mac++)
		for(long long i=0;i<n;i++)
			dp[mac][i]=INF;
	for(long long i=0;i<n;i++) dp[1<<i][i]=0;
	
	for(long long mac=0;mac<(1<<n);mac++){
		for(long long i=0;i<n;i++){
			if(!(mac>>i & 1) || dp[mac][i]==INF) continue;
			for(long long j=0;j<n;j++){
				if((mac>>j & 1) || G[i][j]==INF) continue;
				long long nmac=mac | (1<<j);
				dp[nmac][j]=min(dp[nmac][j],dp[mac][i]+G[i][j]*K[mac]);
			}
		}
	}
	
	cin>>q;
	for(long long i=1;i<=q;i++){
		cin>>X[i]>>U[i]; U[i]--;
		v[i]=X[i];
	}
	sort(v+1,v+q+1);
	vid=unique(v+1,v+q+1)-v-1;
	for(long long i=1;i<=q;i++)
		X[i]=lower_bound(v+1,v+vid+1,X[i])-v;
	
	for(long long i=0;i<n;i++){
		for(long long mac=0;mac<(1<<n);mac++){
			if(dp[mac][i]<INF){
				F[i].P[++F[i].id]={K[mac],-dp[mac][i]};
				F[i].modify(1,vid,1,1,vid,F[i].id);
			}
		}
	}
	
	for(long long i=1;i<=q;i++){
		long long x=X[i],u=U[i];
		long long ans=F[u].query(1,vid,1,x);
		cout<<ans<<'\n';
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 4.16667
Accepted
time: 2ms
memory: 3604kb

input:

2 1
1 10
1 2 10
4
5 1
5 2
100 1
100 2

output:

5
50
100
1090

result:

ok 4 number(s): "5 50 100 1090"

Test #2:

score: 4.16667
Accepted
time: 0ms
memory: 3452kb

input:

4 8
50000000 100000000 20000000 70000000
1 2 20
2 1 50
2 3 90
1 3 40
3 1 10
4 1 25
1 4 5
4 3 70
3
8 3
1000000000 1
500000 4

output:

160000000
239999988050000000
119992550000000

result:

ok 3 number(s): "160000000 239999988050000000 119992550000000"

Test #3:

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

input:

10 90
95677166 99413032 90081107 97391055 96848266 92520734 90623124 96509760 95451402 99152599
1 10 94105173
3 9 91922842
5 2 90862613
8 3 94419460
4 7 90084016
6 4 90693719
10 8 97125103
2 1 93286961
5 10 91546334
4 8 92053784
8 5 96537357
3 1 95913083
1 3 95054163
2 8 95986698
7 6 95233705
8 10 9...

output:

11703326493772984
459620067337423104
200595475148225216
241323875941097376
130998797142629088
58036161281343976
49150655193660864
32449982221768128
380110796421808384
75281539229382960
182007444762360608
32030806118183240
55010947825979440
361567236091527360
112547547611623248
8457348883376196
30891...

result:

wrong answer 2nd numbers differ - expected: '459620067337423078', found: '459620067337423104'

Test #4:

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

input:

10 90
48104151 45958764 10384927 58976477 4508220 48401738 63414134 56241331 43456656 5364282
4 3 34321182
3 8 6111111
10 3 89336838
7 6 15869517
9 6 45416322
6 8 65416493
8 7 68165563
1 10 17098910
5 7 23144280
10 5 41059929
4 5 83655589
8 2 11141593
10 4 47789741
6 4 15702833
6 5 3119771
9 5 79973...

output:

3586313126541447
35983483565665060
4586294248391907
7875951425417254
2259511646032271
9467158922809116
281310401340040640
17521136298708656
62633383479101384
43456656
3514032245442476
374184651748191296
1253158266813619
655602386983086
32349923263050900
772476708605571
49695253783447184
477512507283...

result:

wrong answer 2nd numbers differ - expected: '35983483565665061', found: '35983483565665060'

Test #5:

score: 0
Wrong Answer
time: 101ms
memory: 8464kb

input:

10 87
61275784 16282886 58999609 52155395 53012427 89533414 15431931 35150033 58505854 59445220
9 5 3496028
7 6 17372183
8 1 287847
2 7 19991219
4 5 40820118
4 9 38405375
1 4 52061958
1 3 95765844
9 7 88432897
10 3 62181295
2 4 2070594
6 8 38490628
5 1 74834920
5 2 58054124
5 10 53052912
9 10 799932...

output:

18729278111132296
20776419606475196
8916464253930178
19403717774195936
89156978276985
4658727223980276
8425816213276232
148783617369660
309113940077051840
178911980768416
35871044095338424
9008767024716944
20959051195083680
14730768570927100
3896744071968879
20368652336719224
3286310614587202
560557...

result:

wrong answer 1st numbers differ - expected: '18729278111132298', found: '18729278111132296'

Test #6:

score: 0
Wrong Answer
time: 113ms
memory: 8464kb

input:

10 90
95356560 91592390 93197917 98740065 97680300 92412698 94329246 97243226 90272368 97469569
10 6 99745186
9 3 93877572
4 3 95758698
6 10 91855996
5 1 90121278
5 4 95076290
8 2 99231614
10 3 93399573
4 1 91994993
6 5 94052740
5 2 96068955
2 10 91338395
7 10 91890588
4 7 94880828
1 6 96554961
7 5 ...

output:

163280051600495392
162664925126674112
315043052511946112
34383595644987776
95021580028366160
73642582707231184
1430138781796740
52457131744292840
369797341610245888
22870714303175080
26120943421423424
515435644424449536
24566699865258280
225151095501232704
94961386593212304
242789175852236000
275858...

result:

wrong answer 1st numbers differ - expected: '163280051600495389', found: '163280051600495392'

Test #7:

score: 0
Wrong Answer
time: 91ms
memory: 8460kb

input:

10 89
93795458 90122950 90809309 91512557 99759510 98879743 90406791 91988172 98723686 97265654
3 1 92410620
6 10 787488884
1 7 872243221
5 10 93057933
8 3 90945371
7 4 94869387
1 4 90377187
9 1 92060643
10 8 98532700
9 5 97326866
10 2 98947943
1 6 96415500
10 4 92676865
8 7 92985312
9 6 98444476
1 ...

output:

96011873276486336
19269273838332824
27750185251110900
54768622608712928
63364496816469504
200902549670696736
283398177307668288
136734129505223184
73792577897925696
487594284918169536
96644051419753488
8371064148979270
390528097450315520
423307921353158272
224704322981435232
86859856029482944
400522...

result:

wrong answer 1st numbers differ - expected: '96011873276486328', found: '96011873276486336'

Test #8:

score: 0
Wrong Answer
time: 116ms
memory: 8464kb

input:

10 89
1382293 67193843 93859961 477481 92652257 99885499 50256117 70192761 34119368 16710544
9 10 42167550
5 8 37587488
6 1 39681485
2 6 83885591
2 8 63502599
2 7 96584704
3 2 28849619
1 2 89615158
7 6 49082361
6 7 6114228
6 10 45456432
7 4 87603741
1 8 8377024
5 9 3400067
10 4 42824742
8 1 34659500...

output:

5212184985750879
44473794879167168
34847750171225008
6648241404960350
46013805737436432
90621756903489776
24876175963893520
773327365881191
25315961193668520
33452321319032244
35012500150605
614133199184668
17890608035163296
1380181878519397
1818424411309
4198814378075319
34119368
778135476720094
61...

result:

wrong answer 2nd numbers differ - expected: '44473794879167166', found: '44473794879167168'

Test #9:

score: 0
Wrong Answer
time: 108ms
memory: 8472kb

input:

10 90
97766575 91352441 94775266 90513638 95828190 90356289 90495007 98680228 93010243 98543991
1 3 99109059
5 8 90074960
6 5 90055463
6 1 90819495
8 9 98346448
8 5 90223065
10 9 92780029
3 6 90250424
9 1 96050114
7 3 90956675
4 2 92037130
4 7 90691071
2 3 91565269
8 3 94131990
2 9 97006947
4 10 942...

output:

8773129927176957
176141491594572160
20293571075207244
61165421628826384
176141491594572160
64702906594466208
10883085082295958
192381701219834272
160965364182552192
6191082227085588
182873747067038912
74453900672532960
26275490371094288
124345823804949568
156275640151508032
45662821795014944
3810737...

result:

wrong answer 2nd numbers differ - expected: '176141491594572157', found: '176141491594572160'

Test #10:

score: 0
Wrong Answer
time: 299ms
memory: 87624kb

input:

18 306
97592575 5845225 97094410 61652068 60514373 77053365 82408570 65859870 52309184 11075991 79663473 60429988 64440299 88087418 51883591 39638284 31941363 95790465
18 7 12121248
13 6 28252098
14 12 2481192
4 16 54868108
13 15 33001477
7 13 15911113
8 16 47075458
7 14 51352052
9 2 41100503
18 10 ...

output:

56264701460108256
1285984741468061
28518441564936556
1800078869044666
4233481902785058
18706110257567564
30876640052688400
7267895070590806
10680057213053940
17127903266197332
2811860893998047
35488877575172
564949791756315
35957867675947220
41272735966749120
38034542611577912
6773365701249848
35058...

result:

wrong answer 1st numbers differ - expected: '56264701460108257', found: '56264701460108256'

Test #11:

score: 0
Wrong Answer
time: 285ms
memory: 87576kb

input:

18 306
54786856 23623482 37443275 34976477 27052191 21997277 93803298 62986079 72289998 36640646 66962609 75940630 20835955 36012773 32492294 69398349 49378951 13097897
7 10 5470000
8 7 53513890
3 15 38460382
7 16 19142503
5 14 45517218
18 17 42648313
8 18 48305235
4 16 41424027
5 12 52928903
5 4 44...

output:

16448924998323876
42499474160686928
80574179252365
29157184483740236
16111099859788138
26806493509397012
635257428086302
15906843920014306
1373694291185245
94482938604350
3323915340886396
34889365088369060
2063668366808288
5048756142935801
18314067121808156
39647987073444384
3577563486313359
1358925...

result:

wrong answer 2nd numbers differ - expected: '42499474160686929', found: '42499474160686928'

Test #12:

score: 0
Wrong Answer
time: 273ms
memory: 87696kb

input:

18 303
87437585 22204459 77335222 63373455 24384957 40111770 61538701 65736765 65450807 20008686 60461910 77184085 62951808 75441264 35010255 67513271 41855413 84760939
6 14 45984925
3 6 5610402
8 1 49203830
8 3 53792394
10 8 11629718
1 12 20708032
4 6 14035635
15 18 487975772
3 1 28292662
3 10 2399...

output:

1107904896715516
35056398301693748
9986152964638026
669207273505472384
5651326357638735
5923947474867054
6006244984395488
5893622634689728
9167400465063286
929571390607270272
6645996738166032
8813151760235299
7486719664563380
33431077987813976
221430127060560
5099825435457937
43533336738286496
33171...

result:

wrong answer 4th numbers differ - expected: '669207273505472435', found: '669207273505472384'

Test #13:

score: 0
Wrong Answer
time: 306ms
memory: 87528kb

input:

18 300
95399651 98514702 95906995 99120696 97373712 99841892 95487998 98629037 97207398 99163728 97816361 94919203 95202846 96133518 98849047 99498436 94447669 96164861
10 8 54922237
1 2 55368382
10 4 54029624
9 8 55267410
14 2 53427574
14 18 54579322
3 9 54230956
2 9 52630731
4 16 53837522
3 7 8372...

output:

109547258785001072
83350392507237248
544434800180318720
298383274553068416
103234166632913632
383015478740918400
299473251086849152
147705986455265312
540689651571797056
8303366263580477
622101421737057792
108062600084748960
5862718675123499
227582957640405440
541938177729836032
261012936477036128
3...

result:

wrong answer 1st numbers differ - expected: '109547258785001075', found: '109547258785001072'

Test #14:

score: 0
Wrong Answer
time: 340ms
memory: 87772kb

input:

18 306
94983318 99500146 99056770 99199070 96785433 94689368 96603811 97464542 96757856 95575432 97758260 96271537 94822391 98897205 96531324 95046283 95759027 99689250
14 18 54518764
3 8 54402270
16 8 52601874
3 11 52679529
13 6 54902169
1 10 54363631
4 2 55268135
5 6 52963284
16 1 52494958
12 11 5...

output:

233314656911878880
148725505069721344
131310080408400640
28458149514921784
184841206840838720
86735083994860736
175416255503474624
237843791774471200
107742929277437744
23591406414552200
469643401365794816
16670250600078084
484799960685015616
364831976733288320
11225888146367896
313593053497442112
7...

result:

wrong answer 1st numbers differ - expected: '233314656911878890', found: '233314656911878880'

Test #15:

score: 0
Wrong Answer
time: 321ms
memory: 52520kb

input:

16 240
47666600 44327219 49953274 41785108 32073587 24424080 30939819 78762914 90224099 59998405 64133109 48652631 22221281 96356764 38490560 116991
1 2 91993819
1 3 97619874
1 4 89451708
1 5 79740187
1 6 94041352
1 7 78606419
1 8 126429514
1 9 137890699
1 10 107665005
1 11 111799709
1 12 96319231
1...

output:

212540929497152992
67107116385111424
160830745949979648
58791727813832608
95764761271748272
175339139652863008
239297214240271808
264345302513412640
25916559560778064
108527092089074224
229728402202110560
171112061109054272
127390525466717280
102215300925877904
110949777479288000
8928107215433348
19...

result:

wrong answer 1st numbers differ - expected: '212540929497153000', found: '212540929497152992'

Test #16:

score: 0
Wrong Answer
time: 154ms
memory: 28192kb

input:

16 240
42361838 31647618 32114308 8782634 17345648 68132951 88405030 26942819 62741100 66985295 20876520 8437021 27114112 66925976 7183979 94977427
2 15 58174648
8 15 34276605
6 10 58212397
2 13 58804593
13 9 54225029
15 14 33719184
11 13 61087050
9 10 28955627
6 2 10289499
10 2 20518981
13 8 837959...

output:

493210283393155328
16457452249109400
1426565785333764
2186989187576924
1597997186417782
6058437774768861
7637930712967180
1125270540734250
101052132975905
5643199813537305
10005312013478448
15342932020091028
5252313629194265
173253576572124
16729167032258496
16381630855383736
13698134026929012
13877...

result:

wrong answer 11th numbers differ - expected: '10005312013478447', found: '10005312013478448'

Test #17:

score: 0
Wrong Answer
time: 171ms
memory: 28268kb

input:

16 240
94916675 95328982 94461789 98179130 96410042 95984504 99026406 96722757 98043813 97126519 99521857 99735210 99833885 94048501 93989630 97045699
5 6 61339353
7 11 61447467
16 7 59391553
15 5 61958471
13 2 59603541
13 16 60250166
2 3 61615858
16 3 60312774
14 6 61619256
9 2 61767236
7 12 608785...

output:

690101190008603520
74352044407892896
80895006856543376
46607187491961160
83939049336012160
135104537707913808
18824878173270988
257485548823102496
425301267931667904
6964456929444357
461660068784781440
207874892303542240
369348578117790016
608120982890351616
93344953395804304
675401823119133952
8172...

result:

wrong answer 1st numbers differ - expected: '690101190008603503', found: '690101190008603520'

Test #18:

score: 0
Wrong Answer
time: 242ms
memory: 49352kb

input:

17 269
10989016 28905152 56011456 36383994 32588074 40160206 81943847 29653018 81874689 11531228 28812650 79088847 31042740 89163087 58731031 57356809 5076315
2 4 54972232
1 17 48426734
17 8 7126979
7 2 16376090
10 7 30672058
8 17 55225752
2 6 312152706
4 12 1609956
11 10 44726737
7 6 16333848
17 9 ...

output:

5581509823816012
337248242249304
5660810051537019
239346907640205
7137231109097837
2932413424272456
2147112311279378
2050105075588474
7700720612480128
56134633472252416
4898570036223204
19143181815951648
34279114026302364
54808409846460
65065689951230
55986200355020672
343192271607496
2850473436688
...

result:

wrong answer 10th numbers differ - expected: '56134633472252418', found: '56134633472252416'

Test #19:

score: 0
Wrong Answer
time: 361ms
memory: 60644kb

input:

17 241
20878633 21727433 30788417 1919362 24415556 26527489 14285320 3437901 23517959 28616698 11361867 15220890 21496568 20470194 31073215 5981317 11566475
1 2 42606066
1 3 98682648
1 4 22797995
1 5 45294189
1 6 47406122
1 7 35163953
1 8 24316534
1 9 44396592
1 10 49495331
1 11 32240500
1 12 360995...

output:

108874984881706832
39998804782948736
7253589755190765
47159747035437896
128215794738320320
4126981818415894
17898559608714996
133380710676095344
75180048547321648
131645427536605920
104948693701281264
706440289641834
154697776830457984
6817984851784806
103373859593846192
44351325877615760
1844453686...

result:

wrong answer 1st numbers differ - expected: '108874984881706836', found: '108874984881706832'

Test #20:

score: 0
Wrong Answer
time: 373ms
memory: 60440kb

input:

17 241
26896510 11416857 23632920 22663714 10426416 1449988 6534437 21431904 6332558 5350871 7478640 7144884 1667707 31989074 24328111 14606283 16379885
1 2 38313367
1 3 50529430
1 4 89019020
1 5 37322926
1 6 28346498
1 7 33430947
1 8 48328414
1 9 33229068
1 10 32247381
1 11 48235649
1 12 34041394
1...

output:

32779028068219036
44988444335627296
78532755901649920
69880405813821392
100757975694356960
32737044482112064
10044396653445154
20540412974913928
47761393742370
72716173770109616
176042587180466336
130113285701048912
107065318334030448
103104460019043248
173458077436724608
2650643313873852
1150030928...

result:

wrong answer 1st numbers differ - expected: '32779028068219037', found: '32779028068219036'

Test #21:

score: 0
Wrong Answer
time: 687ms
memory: 106828kb

input:

18 273
5856998 26869251 1761061 23339731 6696975 12073312 26103914 9146585 14284107 2290011 33149581 6690606 1938529 2611081 4180578 15507572 12766646 8196720
1 2 32726249
1 3 7618059
1 4 29196729
1 5 12553973
1 6 17930310
1 7 31960912
1 8 15003583
1 9 20141105
1 10 8147009
1 12 12547604
1 13 779552...

output:

59668433821480728
11829620092917720
94313798310579392
39465910492746704
3287054248487086
93985077914518128
361398308583375
42295501925098912
145833098207262976
169278502787400288
141749264332210048
8905421058615476
166285047110364256
30697972443940536
92813594329636480
13349308698897930
481211077143...

result:

wrong answer 1st numbers differ - expected: '59668433821480730', found: '59668433821480728'

Test #22:

score: 0
Wrong Answer
time: 633ms
memory: 108152kb

input:

18 273
18655021 10530209 4072104 27397860 1799797 31844906 10224838 22363503 8387103 25160565 867464 18587455 28492008 3583506 7250222 12947265 13542506 15353338
1 2 29185230
1 3 22727125
1 4 46052881
1 5 20454818
1 6 50499927
1 8 41018524
1 9 44747129
1 10 43815586
1 11 28438355
1 12 37242476
1 13 ...

output:

191914217942017248
177821186291840096
159567710118372736
63405979674965584
2732703036051690
178142648642986336
6690085357980800
50836174460681760
146778571533991968
105760621215912
14888573155075312
5461385712679200
40061928219653968
12018441115504480
56013237327983424
15564070638837750
137818331953...

result:

wrong answer 1st numbers differ - expected: '191914217942017249', found: '191914217942017248'

Test #23:

score: 0
Wrong Answer
time: 761ms
memory: 112008kb

input:

18 273
18425031 23650394 24880771 20922906 26575943 17784399 1257646 4304768 2028569 32225860 3162758 23575563 21688821 6218252 30502483 720206 33244851 27314277
1 2 43683269
1 3 61643789
1 4 75113213
1 5 58792271
1 6 52052510
1 7 28904939
1 8 22817172
1 9 26122275
1 11 24226530
1 12 77523542
1 13 6...

output:

1138546366805558
62673090797446448
38630509168723288
27245035344721568
98455430479451264
113095555313189904
25219794582211292
201786421030430016
541758543668230
114901795935593632
206619347600715392
197117228100400448
3643777059367880
8397092992289406
3553880571700093
88912148370614544
1788232051772...

result:

wrong answer 5th numbers differ - expected: '98455430479451256', found: '98455430479451264'

Test #24:

score: 0
Wrong Answer
time: 686ms
memory: 111320kb

input:

18 273
26613501 27441209 12794702 13658897 32546072 2607103 21792275 12508707 8092259 2836952 26658654 15275240 16574454 31623641 1150608 21764569 30050392 12599166
1 2 54054710
1 3 39408203
1 4 40272398
1 5 59159573
1 6 29220604
1 7 48405776
1 9 34705760
1 10 29450453
1 11 53272155
1 12 41888741
1 ...

output:

2709709040134800
48604172519557888
530383710482208
2587201659147584
1263375440220300
195656962515960416
8732146742783067
95918983633445952
83061038389120320
180808046186578720
162632332510855520
106925249733973728
218492366742382048
34505908422228720
86963517692649472
59859714929276776
3124459481036...

result:

wrong answer 2nd numbers differ - expected: '48604172519557884', found: '48604172519557888'