QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#211554#5480. New Year Festivalbulijiojiodibuliduo#ML 2335ms623916kbC++172.1kb2023-10-12 18:18:202023-10-12 18:18:21

Judging History

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

  • [2023-10-12 18:18:21]
  • 评测
  • 测评结果:ML
  • 用时:2335ms
  • 内存:623916kb
  • [2023-10-12 18:18:20]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const ll inf=1ll<<60;
const int N=(1<<11)+10;
ll ans=inf;
vector<PII> p[22],bg[22];
int n,l[N],tt[N];
vector<pair<int,ll>> dp[N];
ll calc(int id,int t) {
	if (t<p[id][0].fi) return inf;
	if (t>p[id].back().fi) return inf;
	auto c=lower_bound(all(p[id]),mp(t,-1));
	if (c->fi==t) return c->se;
	auto c0=prev(c);
	return c0->se+(c->se-c0->se)/(c->fi-c0->fi)*(t-c0->fi);
}

int L[22],R[22];
void add(int j,int t) {
	if (t>=L[j]&&t<=R[j]) {
		bg[j].pb(mp(t,calc(j,t)));
	}
}
int main() {
	scanf("%d",&n);
	rep(i,0,n) {
		int m;
		scanf("%d%d",&m,&l[i]);
		rep(j,0,m) {
			int x,y;
			scanf("%d%d",&x,&y);
			p[i].pb(mp(x,y));
		}
		L[i]=p[i][0].fi;
		R[i]=p[i].back().fi;
	}
	rep(S,0,(1<<n)) rep(i,0,n) if (S&(1<<i)) tt[S]+=l[i];
	rep(i,0,n) {
		for (auto [x,y]:p[i]) {
			add(i,x);
			rep(S,0,(1<<n)) if (S&(1<<i)) {
				rep(j,0,n) if (!(S&(1<<j))) {
					add(j,x+tt[S]);
					add(j,x+l[i]-tt[S]-l[j]);
				}
			}

		}
	}
	rep(i,0,n) sort(all(bg[i]));
	dp[0].pb({0,0});
	rep(S,0,(1<<n)) {
		//gao(dp[S]);
		//printf("%d %d\n",S,SZ(dp[S]));
		sort(all(dp[S]));
		rep(j,0,n) if ((S&(1<<j))==0) {
			int r=0;
			ll cs=inf;
			ll pmx=inf;
			for (auto [t,sc]:bg[j]) {
				while (r<SZ(dp[S])&&dp[S][r].fi<=t) {
					cs=min(dp[S][r].se,cs);
					r++;
				}
				if (cs+sc<pmx) {
					pmx=cs+sc;
					dp[S|(1<<j)].pb(mp(t+l[j],cs+sc));
				}
			}
		}
	}
	for (auto [t,sc]:dp[(1<<n)-1]) ans=min(ans,sc);
	printf("%lld\n",ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
3 50
300 2500
350 0
400 3000
2 120
380 0
400 2400
4 160
0 800
400 0
450 100
950 4600

output:

1460

result:

ok single line: '1460'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3736kb

input:

4
2 160
384 0
1000 2464
3 280
0 2646
441 0
1000 2795
1 160
544 0
2 240
720 0
1220 2000

output:

2022

result:

ok single line: '2022'

Test #3:

score: 0
Accepted
time: 2335ms
memory: 623916kb

input:

11
6 192168
0 8547618
626988 33627138
706274 36560720
1103426 50858192
1399013 55291997
1418093 55559117
6 161415
0 58611901
321482 57647455
349707 57534555
550744 55524185
885629 50500910
1448846 27972230
6 195811
0 6825079
56106 8339941
78686 8836701
323216 12993711
525834 15627745
1414450 2095944...

output:

629407685

result:

ok single line: '629407685'

Test #4:

score: 0
Accepted
time: 2136ms
memory: 588496kb

input:

11
6 179446
0 62171637
917478 60336681
1352062 59032929
1368160 58566087
1370260 58503087
1473445 54375687
6 186773
0 2933427
20897 3748410
356883 13827990
1190424 27998187
1340354 29497487
1466118 29623251
6 185925
0 53735520
130212 51652128
582223 42611908
1090981 31419232
1380019 23326168
1466966...

output:

593944734

result:

ok single line: '593944734'

Test #5:

score: 0
Accepted
time: 2075ms
memory: 567480kb

input:

11
6 187590
0 512536
451768 16324416
582142 19714140
1060264 31667190
1212260 33491142
1463556 33742438
6 186786
0 39848792
254907 39084071
928124 31678684
1344556 21684316
1452774 18978866
1464360 18619700
6 177523
0 42981626
30401 42920824
495821 40593724
949343 37419070
1207056 33295662
1473623 2...

output:

568541879

result:

ok single line: '568541879'

Test #6:

score: 0
Accepted
time: 1000ms
memory: 260284kb

input:

11
6 180328
0 70912449
593492 69725465
631349 69119753
934610 63357794
1254206 51852338
1281827 50747498
2 1
543152 90245567
543162 90245567
6 176608
0 46706614
512238 65147182
604236 67263136
771264 69935584
987683 71666936
1285547 72858392
6 169123
0 71973961
349057 70228676
742671 63930852
106384...

output:

728555275

result:

ok single line: '728555275'

Test #7:

score: 0
Accepted
time: 1201ms
memory: 325040kb

input:

11
6 171004
0 62863146
53160 62703666
297997 60500133
928595 50410565
1047846 48383298
1196274 42891462
2 1
497649 90358616
497658 90358616
2 1
877017 61053965
877067 61053965
6 192851
0 73730741
188629 73542112
238857 72939376
589071 62432956
903490 52685967
1174427 43474109
6 165034
0 39275349
288...

output:

684905214

result:

ok single line: '684905214'

Test #8:

score: 0
Accepted
time: 1000ms
memory: 263840kb

input:

11
6 170701
0 66082360
363625 79900110
500001 84400518
1033901 98815818
1139446 99237998
1267187 99493480
2 1
529976 58976463
530026 58976463
6 199596
0 39595850
278702 34857916
365221 32781460
531968 28112544
917360 15009216
1238292 3455664
2 1
729627 23545904
729649 23545904
6 195425
0 21131820
63...

output:

539418869

result:

ok single line: '539418869'

Test #9:

score: 0
Accepted
time: 1124ms
memory: 298328kb

input:

11
2 1
731822 57736604
731847 57736604
6 177906
0 31265048
204117 29632112
367764 26686466
1053673 12282377
1153199 9694701
1266786 6059917
2 1
536410 26155530
536462 26155530
2 1
920218 89157371
920236 89157371
6 173499
0 5971470
368364 19969302
688960 30869566
1086522 43989112
1098619 44364119
127...

output:

615248718

result:

ok single line: '615248718'

Test #10:

score: 0
Accepted
time: 1160ms
memory: 323516kb

input:

11
6 196632
0 70110348
384388 82026376
394546 82199062
763377 86993865
810963 87422139
1260374 90118605
2 1
933046 16939393
933100 16939393
6 173665
0 25812347
235451 34524034
294814 36661102
403393 40352788
999221 58227628
1283341 59648228
6 177710
0 58412603
233394 55145087
426572 50122459
430534 ...

output:

735311761

result:

ok single line: '735311761'

Test #11:

score: 0
Accepted
time: 526ms
memory: 121676kb

input:

11
2 1
327714 97173804
327766 97173804
6 174068
0 97264397
26713 97130832
179562 95143795
858948 81556075
987929 78460531
1015941 77704207
6 175212
0 64880924
252642 73976036
266800 74400776
390959 77132274
806405 81286734
1014797 82953870
6 163249
0 42044695
49476 41747839
197386 40120829
451676 35...

output:

558987902

result:

ok single line: '558987902'

Test #12:

score: 0
Accepted
time: 486ms
memory: 103052kb

input:

11
6 163829
0 31289574
130497 30376095
712717 16402815
753079 15232317
797225 13907937
1066319 3144177
6 168138
0 63124751
45649 64585519
810233 88287623
898033 90658223
905417 90842823
1062010 91312602
6 170025
0 53069325
321981 48561591
591234 41291760
942888 31093794
1024294 28488802
1060123 2705...

output:

569257965

result:

ok single line: '569257965'

Test #13:

score: 0
Accepted
time: 531ms
memory: 111916kb

input:

11
6 167138
0 51023002
165600 56984602
219698 58878032
339095 61146575
892576 71109233
1041644 72748981
2 1
689176 94343012
689249 94343012
6 178942
0 58650734
374 58663824
515755 76186778
947018 84812038
988564 85559866
1029840 85724970
6 173405
0 47201281
229648 55468609
308300 57434909
384679 588...

output:

675590982

result:

ok single line: '675590982'

Test #14:

score: 0
Accepted
time: 493ms
memory: 115596kb

input:

11
6 174305
0 94317116
156381 93066068
738860 83163925
801318 81914765
1058316 74461823
1076858 73738685
6 187492
0 57378030
357720 70255950
383079 70940643
538696 74519834
830802 80946166
1063671 84439201
6 179318
0 62479756
269535 70565806
281413 70874634
634924 74763255
916720 75608643
1071845 75...

output:

712616989

result:

ok single line: '712616989'

Test #15:

score: 0
Accepted
time: 512ms
memory: 115936kb

input:

11
6 181795
0 17122556
102744 21129572
299317 28009627
806065 45239059
921763 47553019
1095305 48420729
6 190533
0 42602682
10275 43003407
180188 48610536
865763 67806636
939173 69715296
1086567 71631418
2 1
529036 58707251
529083 58707251
2 1
917587 10593491
917630 10593491
6 166172
0 73743543
1369...

output:

542369675

result:

ok single line: '542369675'

Test #16:

score: 0
Accepted
time: 257ms
memory: 29604kb

input:

11
2 1
727800 20498697
727829 20498697
6 177706
0 21250146
38893 21133467
250783 20285907
792887 8359619
798142 8191459
884652 5163609
6 162623
0 14906340
379619 30091100
415655 31424432
559643 35888060
746934 39821171
899735 42571589
6 179608
0 11941388
203734 19479546
321997 23263962
444492 265713...

output:

432748635

result:

ok single line: '432748635'

Test #17:

score: 0
Accepted
time: 252ms
memory: 28548kb

input:

11
2 1
331882 64233485
331943 64233485
6 161328
0 26996144
322377 22805243
707171 16648539
771738 15357199
776897 15248860
867217 12448940
2 1
867971 91310630
867989 91310630
6 160555
0 78199529
86753 80715366
401127 88574716
504487 90848636
790264 95135291
867990 95290743
2 1
703673 27828123
703687...

output:

683878583

result:

ok single line: '683878583'

Test #18:

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

input:

11
6 174316
0 47897162
641806 72927596
644242 73010420
755581 76016573
811250 76628932
893211 76792854
6 166188
0 66549903
71840 66406223
119861 65877992
325611 62791742
616567 54644974
901339 44393182
6 165579
0 1031241
48042 2760753
196253 5724973
535978 10820848
581549 11003132
901948 11964329
2 ...

output:

619086324

result:

ok single line: '619086324'

Test #19:

score: 0
Accepted
time: 236ms
memory: 34528kb

input:

11
6 167704
0 58832679
370569 55868127
626169 53567727
663624 52781172
836807 47412499
898647 45309939
6 178808
0 88894906
243375 88164781
297907 87946653
335037 87315443
849159 75490637
887543 74032045
2 1
730898 45305194
730922 45305194
2 1
167710 57873219
167770 57873219
2 1
346582 81704091
34665...

output:

584549217

result:

ok single line: '584549217'

Test #20:

score: 0
Accepted
time: 253ms
memory: 31440kb

input:

11
6 172855
0 42531672
172560 42186552
638982 36123066
740826 34697250
880888 31896010
912058 30960910
2 1
172859 87907354
172901 87907354
2 1
913759 84347576
913770 84347576
2 1
737496 15253290
737524 15253290
2 1
550983 60643609
551035 60643609
6 194108
0 64902863
18457 64810578
217247 61431148
54...

output:

597390225

result:

ok single line: '597390225'

Test #21:

score: 0
Accepted
time: 11ms
memory: 3896kb

input:

11
2 1
531 70843885
615 70843885
2 1
343 58517596
443 58517596
2 1
215 65255473
306 65255473
2 1
1 85022551
78 85022551
2 1
308 25241720
339 25241720
2 1
451 26840810
529 26840810
2 1
209 65672580
210 65672580
2 1
658 10786993
725 10786993
2 1
139 59113224
207 59113224
2 1
88 31479467
130 31479467
2...

output:

529410596

result:

ok single line: '529410596'

Test #22:

score: 0
Accepted
time: 3ms
memory: 3860kb

input:

11
3 10
11 10000000
12 0
13 10000000
3 20
21 10000000
22 0
23 10000000
3 40
41 10000000
42 0
43 10000000
3 80
81 10000000
82 0
83 10000000
3 160
161 10000000
162 0
163 10000000
3 320
321 10000000
322 0
323 10000000
3 640
641 10000000
642 0
643 10000000
3 1280
1281 10000000
1282 0
1283 10000000
3 256...

output:

0

result:

ok single line: '0'

Test #23:

score: 0
Accepted
time: 668ms
memory: 116952kb

input:

11
3 100000
100100 10000000
100101 0
100102 10000000
4 1
99999 10000000
100000 101022
201022 0
201023 10000000
4 2
99999 10000000
100000 0
201021 101021
201022 10000000
4 4
99999 10000000
100000 101019
201019 0
201020 10000000
4 8
99999 10000000
100000 0
201015 101015
201016 10000000
4 16
99999 1000...

output:

1004939

result:

ok single line: '1004939'

Test #24:

score: 0
Accepted
time: 322ms
memory: 54584kb

input:

11
1 1
309 0
2 1
0 1023
1023 0
2 2
0 0
1022 1022
2 4
0 1020
1020 0
2 8
0 1016
1016 0
2 16
0 0
1008 1008
2 32
0 0
992 992
2 64
0 0
960 960
2 128
0 0
896 896
2 256
0 768
768 0
2 512
0 0
512 512

output:

3669

result:

ok single line: '3669'

Test #25:

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

input:

5
5 14740
0 98138440
83236395 98138440
83236396 35898835
83236397 98138440
100000000 98138440
5 18569
0 69878160
42264949 69878160
42264950 68129173
42264951 69878160
100000000 69878160
5 63770
0 65429428
25122042 65429428
25122043 24329432
25122044 65429428
100000000 65429428
5 92572
0 96131514
801...

output:

234464013

result:

ok single line: '234464013'

Test #26:

score: 0
Accepted
time: 762ms
memory: 9008kb

input:

11
5 89
0 84080533
74506841 84080533
74506842 83055856
74506843 84080533
100000000 84080533
5 18029
0 68815953
58287635 68815953
58287636 31497588
58287637 68815953
100000000 68815953
5 7715
0 79502447
7136910 79502447
7136911 13979205
7136912 79502447
100000000 79502447
5 11560
0 58769677
67015775 ...

output:

440961880

result:

ok single line: '440961880'

Test #27:

score: 0
Accepted
time: 763ms
memory: 8904kb

input:

11
5 2698
0 63263164
66665684 63263164
66665685 12537879
66665686 63263164
100000000 63263164
5 9253
0 70064791
71124688 70064791
71124689 12447768
71124690 70064791
100000000 70064791
5 9665
0 43423649
7917397 43423649
7917398 38665078
7917399 43423649
100000000 43423649
5 5215
0 82395135
51019869 ...

output:

359536961

result:

ok single line: '359536961'

Test #28:

score: 0
Accepted
time: 762ms
memory: 8932kb

input:

11
5 1287
0 99700224
43078236 99700224
43078237 32239297
43078238 99700224
100000000 99700224
5 646
0 84365409
92891364 84365409
92891365 83498178
92891366 84365409
100000000 84365409
5 1078
0 96232878
54897379 96232878
54897380 5160197
54897381 96232878
100000000 96232878
5 2004
0 89863504
10033003...

output:

431514624

result:

ok single line: '431514624'

Test #29:

score: 0
Accepted
time: 761ms
memory: 8696kb

input:

11
5 1857
0 10567270
12172120 10567270
12172121 5059407
12172122 10567270
100000000 10567270
5 2958
0 71107715
44938306 71107715
44938307 53838592
44938308 71107715
100000000 71107715
5 1581
0 22304137
62454662 22304137
62454663 21736631
62454664 22304137
100000000 22304137
5 3027
0 29690364
1835435...

output:

327642379

result:

ok single line: '327642379'

Test #30:

score: 0
Accepted
time: 0ms
memory: 3760kb

input:

2
42 405378
36496 5015
43771 979865
147119 8937661
159331 3039265
172427 5121529
192386 5460832
228141 6497727
243862 3935204
265484 0
269472 3130580
300411 1057667
304392 6065765
312785 8399019
379235 4810719
398643 2637023
404627 4869055
410171 2158039
411974 7823065
433397 2788660
443308 3175189
...

output:

1804577

result:

ok single line: '1804577'

Test #31:

score: 0
Accepted
time: 1ms
memory: 3860kb

input:

3
22 317500
255 7210390
8996 9491791
52506 4575161
93039 4250897
110938 2496795
127210 641787
192847 9043323
200707 625263
222630 4374096
252684 1158318
322292 2550478
354299 117946
392964 8237596
397040 0
453812 7210044
478158 7283082
708482 7283082
712198 8628274
771803 5886444
791054 6964500
8370...

output:

1057822

result:

ok single line: '1057822'

Test #32:

score: 0
Accepted
time: 1ms
memory: 3812kb

input:

4
13 107993
21446 2034716
117649 7229678
141188 5064090
268063 7728465
345299 6260981
491051 4074701
590292 7250413
821431 7943830
830513 6754088
903927 0
941793 5755632
941876 8147194
986049 4039105
9 95854
321155 5938108
396413 5561818
421102 5907464
470068 6152294
552962 3997050
576778 3997050
58...

output:

1121404

result:

ok single line: '1121404'

Test #33:

score: 0
Accepted
time: 1ms
memory: 3952kb

input:

5
2 225905
456408 3650768
539380 0
16 104849
40 7389926
471 1487381
100932 8620112
177348 1437008
431414 8042724
467448 4367256
487678 7806356
573358 5492996
589670 3910732
676057 9439500
730307 0
772102 1546415
775933 6304517
876605 1774277
910140 8783092
988999 2632090
23 26630
22225 6838610
49369...

output:

1525048

result:

ok single line: '1525048'

Test #34:

score: 0
Accepted
time: 3ms
memory: 4340kb

input:

6
15 49968
66893 5100254
417974 6504578
430686 6491866
458738 9128754
475590 9583758
531009 8586216
558233 1480752
561586 5524470
614296 1465800
684096 0
737656 5302440
763835 6271063
766533 208657
909458 6497357
970436 9363323
4 164622
93905 0
691830 5979250
806660 4027140
905184 4027140
5 109903
6...

output:

1769547

result:

ok single line: '1769547'

Test #35:

score: 0
Accepted
time: 9ms
memory: 6240kb

input:

7
5 74346
105005 1819846
252818 3002350
349668 0
487807 1381390
740821 2140432
8 152699
231162 5211097
248085 1961881
687966 5041048
799319 2479929
852393 3276039
857002 1796550
918952 0
999068 3925684
7 50811
293759 4444932
445835 5661540
458615 0
491668 8263250
579614 4745410
810087 9354870
940735...

output:

0

result:

ok single line: '0'

Test #36:

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

input:

8
1 37469
534670 0
10 35922
71851 0
100528 7914852
243973 5189397
296761 8198313
356888 682438
449022 1972314
607047 1498239
828831 832887
886215 5595759
986874 1166763
15 35368
4624 7893274
86286 6015048
123626 3251888
182560 4312700
406012 7441028
510197 7128473
568501 4329881
579765 2933145
60087...

output:

3443255

result:

ok single line: '3443255'

Test #37:

score: 0
Accepted
time: 105ms
memory: 31468kb

input:

9
6 40106
63839 4654148
172075 0
176476 3842073
274802 3547095
804770 3547095
959281 2156496
6 65481
150979 0
437256 0
501270 2176476
540662 1428028
624793 5129792
747239 3782886
2 107202
658940 0
752832 4319032
7 54836
373459 1390847
373970 4678110
479040 2156430
558823 6704061
745570 1661892
88406...

output:

1318930

result:

ok single line: '1318930'

Test #38:

score: 0
Accepted
time: 439ms
memory: 135856kb

input:

10
4 34244
80506 0
342904 5247960
890989 1959450
904247 2715156
2 62598
21700 0
768989 4483734
4 92371
732330 0
891383 6044014
931022 6400765
985380 4933099
1 110905
482882 0
3 65297
173067 3204616
264991 2285376
645887 0
20 104541
62453 794911
75744 7533448
208150 3428862
254887 6420030
260302 4865...

output:

4873647

result:

ok single line: '4873647'

Test #39:

score: 0
Accepted
time: 1584ms
memory: 388144kb

input:

11
1 60894
282075 0
8 71802
168015 6608472
336025 6944492
488316 3441799
546304 8544743
777243 0
849821 9217406
906124 321532
944011 5360503
7 21308
14119 100257
197219 1198857
306206 0
461150 464832
578791 935396
679071 5046876
933316 5301121
3 21604
72773 1209266
174162 6684272
412886 0
4 77207
72...

output:

2362383

result:

ok single line: '2362383'

Test #40:

score: -100
Memory Limit Exceeded

input:

11
9 80441
229094 1815190
243702 383606
282897 4616666
476936 1512042
824937 2904046
831273 3062446
889055 0
915728 1200285
981607 1661438
2 6925
126477 5334102
719155 0
2 20926
109365 2822724
815046 0
1 86930
353711 0
4 39324
395570 2680881
465734 5136621
514293 2611553
887372 0
1 93906
141343 0
12...

output:

437384

result: