QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#51360#1876. MIPT: Connecting PeopletricyzhkxAC ✓1248ms360008kbC++142.2kb2022-10-02 11:32:372022-10-02 11:32:38

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-02 11:32:38]
  • 评测
  • 测评结果:AC
  • 用时:1248ms
  • 内存:360008kb
  • [2022-10-02 11:32:37]
  • 提交

answer

# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[70],sum[70],tv[70],id[70][3010],L[70][3010],R[70][3010];
ll f[3001][61][61],g[3001][61][61],h[3001][61][61],mnL[3001][61][61],mnR[3001][61][61];
void upd(ll &a,ll b){a>b?a=b:0;}
int main()
{
	int n,th,tot=0;
	cin>>n>>th;
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&tv[i]),sum[i]=sum[i-1]+a[i];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=a[i];j++)
			id[i][j]=++tot;
	for(int i=0;i<=tot;i++)
		for(int j=1;j<=n;j++)
			for(int k=j;k<=n;k++)
				f[i][j][k]=g[i][j][k]=h[i][j][k]=mnL[i][j][k]=mnR[i][j][k]=1e18;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=a[i];j++)
		{
			int p;
			for(p=i-1;p && a[p]<j;p--);
			L[i][j]=p;
			for(p=i+1;p<=n && a[p]<j;p++);
			R[i][j]=p;
		}
	auto calc=[&](ll w,int sz){return w*sz*(tot-sz);};
	for(int l=1;l<=n+1;l++)
		for(int i=1;i<=n;i++)
			for(int j=a[i];j>=1;j--)
				h[id[i][j]][l][l-1]=h[id[i][j+1]][l][l-1]+calc(tv[i],a[i]-j+1);
	for(int l=n;l>=1;l--)
		for(int r=l;r<=n;r++)
		{
			for(int i=l;i<=r;i++)
				for(int j=1;j<=a[i];j++)
				{
					int pl=L[i][j],pr=R[i][j],k=id[i][j],kl=id[pl][j],kr=id[pr][j],k2=id[i][j-1];
					auto G=[&](int l,int r){return k2?g[k2][l][r]:(l==i && r==i?0:1e18);};
					for(int m=l-1;m<i;m++) upd(mnL[k][l][r],f[kl][l][m]+G(m+1,r));
					for(int m=i;m<=r;m++) upd(mnR[k][l][r],G(l,m)+f[kr][m+1][r]);
					for(int m=i;m<=r;m++) upd(g[k][l][r],mnL[k][l][m]+f[kr][m+1][r]);
					g[k][l][r]+=calc(tv[i],sum[r]-sum[l-1]-a[i]+j);
					k2=id[i][j+1];
					for(int m=i;m<=r;m++) upd(f[k][l][r],mnR[k][l][m]+h[k2][m+1][r]);
					for(int m=l-1;m<i;m++) upd(f[k][l][r],h[k2][l][m]+mnL[k][m+1][r]);
					f[k][l][r]+=calc(th,sum[r]-sum[l-1]);
				}
			for(int i=1;i<l;i++)
				for(int j=a[i];j>=1;j--)
				{
					int p=R[i][j],k=id[i][j],k1=id[p][j],k2=id[i][j+1];
					for(int m=l-1;m<=r;m++) upd(h[k][l][r],f[k1][l][m]+h[k2][m+1][r]);
					h[k][l][r]+=calc(tv[i],a[i]-j+1+sum[r]-sum[l-1]);
				}
			for(int i=r+1;i<=n;i++)
				for(int j=a[i];j>=1;j--)
				{
					int p=L[i][j],k=id[i][j],k1=id[p][j],k2=id[i][j+1];
					for(int m=l-1;m<=r;m++) upd(h[k][l][r],h[k2][l][m]+f[k1][m+1][r]);
					h[k][l][r]+=calc(tv[i],a[i]-j+1+sum[r]-sum[l-1]);
				}
		}
	cout<<f[id[1][a[1]]][1][n]<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3880kb

input:

1 1
5 1

output:

20

result:

ok answer is '20'

Test #2:

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

input:

2 1
3 3
3 2

output:

59

result:

ok answer is '59'

Test #3:

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

input:

5 1000
10 1
1 1
7 1
3 1
8 1

output:

460314

result:

ok answer is '460314'

Test #4:

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

input:

5 1
10 1000
1 1000
7 1000
3 1000
8 1000

output:

1626464

result:

ok answer is '1626464'

Test #5:

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

input:

1 414619
100 498997

output:

83157850050

result:

ok answer is '83157850050'

Test #6:

score: 0
Accepted
time: 13ms
memory: 65100kb

input:

1 144052
3000 309889

output:

1394500345055500

result:

ok answer is '1394500345055500'

Test #7:

score: 0
Accepted
time: 2ms
memory: 6072kb

input:

2 76800
65 647554
35 185123

output:

60514170820

result:

ok answer is '60514170820'

Test #8:

score: 0
Accepted
time: 13ms
memory: 72464kb

input:

2 256220
1963 311961
1037 530722

output:

1137091926771735

result:

ok answer is '1137091926771735'

Test #9:

score: 0
Accepted
time: 2ms
memory: 6356kb

input:

3 706278
31 369111
56 923899
13 865399

output:

83196440515

result:

ok answer is '83196440515'

Test #10:

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

input:

10 26988
2 524303
2 155871
5 529858
5 738490
6 611743
9 190337
11 321000
16 768996
19 139086
25 129074

output:

12630754247

result:

ok answer is '12630754247'

Test #11:

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

input:

15 493819
1 60941
1 504136
4 823213
4 337706
6 752723
8 981650
8 417667
10 82528
15 749793
15 64009
20 505391
24 509759
25 368532
25 570000
34 891167

output:

161899980099

result:

ok answer is '161899980099'

Test #12:

score: 0
Accepted
time: 5ms
memory: 23968kb

input:

20 774273
57 98503
54 987715
28 497327
28 322838
24 602203
19 826069
17 54268
17 245979
12 10461
9 278770
8 59419
5 919077
5 914772
4 215123
4 328862
3 793413
2 860603
2 599363
1 629514
1 228067

output:

540329602056

result:

ok answer is '540329602056'

Test #13:

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

input:

30 700778
22 619045
19 292419
16 617155
15 846390
14 239675
11 487485
10 889944
9 564266
8 825369
5 6740
3 172641
2 200875
2 400754
1 19725
1 353498
1 291351
1 268204
2 557821
2 160819
2 200542
3 658532
5 25106
5 94162
7 373318
15 62374
17 647947
17 862222
19 278058
26 433781
40 600187

output:

401215134717

result:

ok answer is '401215134717'

Test #14:

score: 0
Accepted
time: 109ms
memory: 133100kb

input:

35 722567
1 200872
1 514068
1 10665
4 374744
4 299692
5 866972
6 904423
10 469940
11 459022
11 22654
14 883138
15 563323
16 338439
16 460833
18 417530
19 391982
20 665025
27 566400
28 936516
32 335843
34 564059
35 380715
36 155911
41 982212
42 583398
43 730823
44 656034
49 642702
49 399146
65 227978...

output:

24925315532374

result:

ok answer is '24925315532374'

Test #15:

score: 0
Accepted
time: 214ms
memory: 196292kb

input:

40 859188
1 127057
3 421607
3 258208
4 462623
5 884519
7 326001
7 952440
10 234729
11 58711
12 534179
15 249916
16 21348
20 936791
20 615047
20 291731
26 660955
28 956574
29 975947
30 972009
31 690943
32 689772
42 162754
43 668780
44 786533
44 115328
46 860514
49 779024
51 647235
56 780064
58 660932...

output:

45832150212339

result:

ok answer is '45832150212339'

Test #16:

score: 0
Accepted
time: 362ms
memory: 217352kb

input:

45 681930
17 596186
47 231915
75 202526
82 294928
145 985178
121 252917
105 775694
82 802120
80 232962
76 771486
69 949527
60 180712
51 92888
49 646820
41 611477
40 328789
40 278962
39 93237
33 247996
32 232042
29 521340
29 92600
29 599952
26 299255
24 616182
24 185925
23 657195
21 286077
20 829940
...

output:

39420897223318

result:

ok answer is '39420897223318'

Test #17:

score: 0
Accepted
time: 383ms
memory: 217892kb

input:

50 95214
120 539289
93 685661
88 431030
68 61430
62 197898
61 326417
55 81099
47 514463
46 820102
45 867988
41 80326
40 528879
38 440444
35 354615
33 789276
31 801670
31 557636
25 876106
25 265315
24 305354
23 954328
23 550375
22 278809
13 486948
12 943638
12 36968
12 201757
11 335681
10 575487
9 55...

output:

18366752576638

result:

ok answer is '18366752576638'

Test #18:

score: 0
Accepted
time: 57ms
memory: 95900kb

input:

30 640639
91 280493
53 947710
46 831222
46 163409
42 997956
39 522732
38 948925
31 461777
19 658490
15 83150
2 819526
2 625759
2 718821
3 64080
8 716695
8 566438
14 698013
14 896512
15 399804
18 190072
18 215168
20 369742
24 825603
28 610055
35 447535
54 69650
79 314176
79 886189
81 147854
87 414598

output:

9169451983590

result:

ok answer is '9169451983590'

Test #19:

score: 0
Accepted
time: 44ms
memory: 92980kb

input:

20 606776
83 41819
4 466421
12 805260
2 653965
1 931711
5 241476
20 201338
9 188845
34 394803
156 948091
21 612355
76 929434
148 195290
169 539644
58 977331
47 237873
100 350856
149 868155
151 232391
93 603553

output:

33506308793328

result:

ok answer is '33506308793328'

Test #20:

score: 0
Accepted
time: 109ms
memory: 125040kb

input:

30 223727
12 252140
6 349138
92 466904
139 722082
38 362824
15 595419
9 584282
3 470727
39 845558
63 378120
10 359927
15 248412
45 174800
127 901793
103 29037
14 559131
19 678872
36 370933
142 765470
94 543813
10 699506
13 513620
14 737104
77 878940
97 407077
7 769427
1 300525
26 765224
65 348701
1 ...

output:

28208163341309

result:

ok answer is '28208163341309'

Test #21:

score: 0
Accepted
time: 167ms
memory: 88084kb

input:

60 265406
1 756550
1 429646
1 390955
1 208173
1 203516
2 838949
2 381413
2 276474
2 136508
2 373655
2 401746
3 687626
3 418700
3 325297
3 257521
3 598901
3 103748
3 74743
4 602261
4 390729
4 497171
4 301088
4 937958
4 795143
5 929531
5 561749
5 804703
6 40610
6 193937
7 429046
7 31249
7 909379
7 602...

output:

1471812853452

result:

ok answer is '1471812853452'

Test #22:

score: 0
Accepted
time: 1248ms
memory: 360008kb

input:

60 346466
1 475541
1 909687
1 967904
2 11171
2 270489
3 322884
3 207756
7 653301
7 131127
8 732628
8 355892
10 951426
10 555421
13 984871
13 856555
13 103416
13 892832
14 29820
16 445222
21 339659
21 748344
23 598297
24 164673
25 947250
27 170434
30 321286
31 923320
33 500200
33 695037
33 669266
33 ...

output:

66837998781548

result:

ok answer is '66837998781548'

Test #23:

score: 0
Accepted
time: 658ms
memory: 184564kb

input:

60 73484
1 57880
1 351733
1 82619
2 960983
3 899700
4 298413
5 274531
6 12142
13 179072
14 417833
21 991463
21 263717
24 511061
33 624201
34 759667
42 941182
42 373908
50 365970
54 624763
63 909535
80 858591
77 146796
77 230769
44 405970
42 988765
42 167266
35 960336
33 752198
31 80314
26 516005
25 ...

output:

10094984905612

result:

ok answer is '10094984905612'

Test #24:

score: 0
Accepted
time: 836ms
memory: 285720kb

input:

60 226757
160 683460
159 593427
151 942934
85 716142
79 291787
78 720545
62 28770
49 966755
46 479002
42 314007
41 876836
39 421418
37 234265
36 868575
36 12654
34 213799
33 620325
33 97653
31 8134
25 665234
24 600655
24 149613
24 113448
23 372853
23 795162
22 533355
21 855042
20 384882
17 905281
16...

output:

51467901727786

result:

ok answer is '51467901727786'

Test #25:

score: 0
Accepted
time: 718ms
memory: 210136kb

input:

60 771670
47 2985
3 320750
10 96990
65 5490
22 11993
2 64893
26 29645
17 16758
18 52512
2 282603
19 28346
36 22625
16 59836
2 214828
10 81193
10 34494
31 9661
2 9305
26 5511
35 662
6 91533
2 345069
27 27510
43 21305
51 15018
3 247323
20 19624
17 53193
27 19045
1 752431
10 36221
89 9525
13 17576
1 83...

output:

3340713056515

result:

ok answer is '3340713056515'

Test #26:

score: 0
Accepted
time: 881ms
memory: 228668kb

input:

60 449855
1 289075
64 11476
3 278185
4 215761
2 211290
14 11818
1 324724
64 10234
12 70719
3 215123
2 306920
59 14017
32 26727
36 16948
1 253336
4 116572
75 8907
71 10708
54 7621
1 536933
8 61883
7 101819
79 9981
31 13723
1 253370
1 593361
42 12161
95 4135
50 8984
4 174789
17 36489
53 17931
70 4116
...

output:

2593239136575

result:

ok answer is '2593239136575'

Test #27:

score: 0
Accepted
time: 596ms
memory: 175684kb

input:

60 1000000
32 591475
92 46411
53 892519
46 337562
1 135221
10 358346
16 858774
22 593249
1 79108
7 931579
14 411440
27 992221
19 441913
8 200138
6 957978
9 174357
3 4195
4 6135
66 702123
48 237858
11 748996
21 829717
25 873840
23 655794
6 848212
1 428365
24 434091
23 702662
4 527997
5 374425
19 9525...

output:

11357940055834

result:

ok answer is '11357940055834'