QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#357520#3056. Live ProgrammingKevin5307WA 16ms74020kbC++201.5kb2024-03-18 22:16:012024-03-18 22:16:02

Judging History

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

  • [2024-03-18 22:16:02]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:74020kb
  • [2024-03-18 22:16:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int n,t;
ll f[4004],p[4004],l[4004];
ll dp[4004][4004];
deque<pair<ll,ll>> dq[4004];
struct fraction
{
	ll x,y;
	fraction(){}
	fraction(ll x,ll y):x(x),y(y){}
	const friend bool operator <(const fraction &a,const fraction &b)
	{
		return a.x*b.y<a.y*b.x;
	}
};
fraction slope(pair<ll,ll> a,pair<ll,ll> b)
{
	return fraction((b.first-a.first),(b.second-a.second));
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>t;
	for(int i=1;i<=n;i++)
		cin>>l[i]>>p[i]>>f[i];
	for(int i=1;i<=n;i++)
		for(int j=1;j<n;j++)
			if(f[j]>f[j+1])
			{
				swap(f[j],f[j+1]);
				swap(p[j],p[j+1]);
				swap(l[j],l[j+1]);
			}
	for(int i=0;i<=n;i++)
		for(int j=0;j<=t;j++)
			dp[i][j]=-1e14;
	dp[0][0]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=t;j++) if(dp[i-1][j]>=-1e13)
		{
			ll vy=dp[i-1][j]-f[i-1]*f[i-1];
			ll vx=f[i-1]+f[i-1];
			while(dq[j].size()>1&&slope(dq[j][dq[j].size()-2],dq[j].back())<slope(dq[j].back(),pair<ll,ll>(vy,vx)))
				dq[j].pop_back();
			dq[j].emplace_back(vy,vx);
		}
		for(int j=0;j<=t-l[i];j++) if(dq[j].size())
		{
			while(dq[j].size()>1&&fraction(-f[i],1)<slope(dq[j][0],dq[j][1]))
				dq[j].pop_front();
			dp[i][j+l[i]]=dq[j][0].first+dq[j][0].second*f[i]-f[i]*f[i]+p[i];
		}
		dp[i][l[i]]=max(dp[i][l[i]],p[i]);
	}
	ll ans=0;
	for(int i=0;i<=n;i++)
		for(int j=0;j<=t;j++)
			ans=max(ans,dp[i][j]);
	cout<<ans<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 10
10 200 1
10 100 100

output:

200

result:

ok single line: '200'

Test #2:

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

input:

3 15
5 100 1
5 100 2
5 100 4

output:

295

result:

ok single line: '295'

Test #3:

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

input:

3 10
5 200 200
5 200 201
5 300 1

output:

399

result:

ok single line: '399'

Test #4:

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

input:

3 20
5 100 200
5 100 201
5 300 1

output:

300

result:

ok single line: '300'

Test #5:

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

input:

5 61
14 49 7
31 46 4
30 55 5
52 99 1
34 70 3

output:

103

result:

ok single line: '103'

Test #6:

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

input:

42 16
16 72073499 4632
1 18467047 9046
14 31273517 3525
3 43577541 4655
1 31950136 410
3 35007694 5797
9 49328891 4854
2 74367508 7864
7 51170926 6563
4 77856895 784
1 78297498 3393
16 77127326 8501
16 71424103 6731
4 61491251 9925
3 76313409 4018
4 59712678 2624
5 43021655 9439
10 14064673 6791
4 1...

output:

448259665

result:

ok single line: '448259665'

Test #7:

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

input:

64 17
13 23916157 888
1 22334161 8106
5 64756275 9683
11 30753510 5644
7 94891777 3978
12 55980188 427
6 6540494 6728
3 98108147 3243
4 97266872 5008
2 67036662 869
7 10060360 9008
16 54165933 2716
14 2836966 6200
11 95955330 8715
8 78063765 6641
1 70178421 9095
17 88168595 861
5 32864912 497
11 176...

output:

579504064

result:

ok single line: '579504064'

Test #8:

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

input:

46 16
14 81598337 3552
11 88196612 3612
6 19284768 8025
15 94746496 640
10 38944210 9658
9 83707521 8401
12 74473205 2793
7 95611173 5014
7 32689034 6079
4 85474165 3828
4 32475219 3333
10 86932984 8988
10 84739464 202
5 33650562 3173
16 83135736 2238
3 42763804 861
7 33345463 3510
4 80045035 8420
1...

output:

485842176

result:

ok single line: '485842176'

Test #9:

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

input:

83 18
5 26109671 5229
9 5869134 8624
17 68285176 5334
17 25966106 9778
10 99012646 6103
8 36881819 350
6 68916818 4268
5 12416787 2059
12 33926135 8430
13 53053393 28
16 37917483 3939
13 69640803 8622
8 58733914 5754
12 45812390 1939
11 28539882 6776
3 22976416 1198
13 57192555 4131
7 49897524 2425
...

output:

531995609

result:

ok single line: '531995609'

Test #10:

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

input:

27 15
5 77446548 5081
10 44320822 7153
6 84527050 9258
7 21481696 5028
13 30193873 4597
15 60993463 505
9 50705149 1269
14 60112392 9949
15 37189654 5763
11 28439956 8197
5 41786770 6315
1 11584464 1052
14 70218645 3449
5 60451409 8298
10 71696550 2703
5 26454699 8541
5 70627710 9987
14 66906649 826...

output:

239424098

result:

ok single line: '239424098'

Test #11:

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

input:

79 16
12 37122590 8434
16 36047757 3933
6 92059912 1419
13 88871914 7686
14 57455124 4481
11 48623936 7290
4 88768842 4194
8 7423394 2638
16 46806688 8799
10 63145519 6442
4 17430787 3219
5 40769755 9071
13 26919811 5465
9 91749043 7660
13 16216543 9099
6 81862394 474
8 39107921 7219
15 28979566 800...

output:

519730524

result:

ok single line: '519730524'

Test #12:

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

input:

48 12
2 4646818 666
3 88260305 8335
8 59021859 6524
6 35794089 3133
7 94155606 4497
4 81614809 2095
9 64147226 4085
7 69078705 6681
12 17700055 5282
3 24315032 4590
2 69975114 818
10 59495399 1905
4 65190135 6105
5 21551800 946
3 27596797 2663
6 10757603 7745
5 258958 8215
1 74731249 8172
7 46639577...

output:

520273468

result:

ok single line: '520273468'

Test #13:

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

input:

75 13
7 94331647 6193
13 80404992 7
8 66203187 199
2 85139526 3649
7 20011372 5657
10 26593330 6819
2 84322268 9858
5 26098094 3039
10 65390456 9232
1 54845879 1406
3 50242479 5693
11 47678893 1254
11 72624601 6191
2 95744917 2705
9 64216241 1633
10 3391876 9531
10 57800618 196
2 69415076 9220
1 800...

output:

659466995

result:

ok single line: '659466995'

Test #14:

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

input:

76 14
7 35720038 6189
7 95147273 7448
2 66389185 2399
14 91945044 9925
9 95763495 7400
9 59066766 8511
8 58533280 4785
8 98657793 6785
3 48637340 6118
2 44011086 565
6 37267686 9429
7 64214239 3355
3 29549884 9361
11 86549276 9162
12 42712794 2273
5 40439365 4775
14 1504459 4199
10 62357906 6461
11 ...

output:

395962320

result:

ok single line: '395962320'

Test #15:

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

input:

59 13
4 26703215 7701
6 64093157 9927
8 1190305 6862
3 27259567 1263
5 87320488 4726
5 8514068 5928
12 41959224 9674
13 47118837 2277
13 71316772 34
3 64744216 5802
10 39623039 8418
11 33619746 2729
1 17573922 1329
2 60255675 9802
5 9231818 6421
4 59481829 3360
13 12077561 7829
4 7146913 7203
8 5915...

output:

443826668

result:

ok single line: '443826668'

Test #16:

score: -100
Wrong Answer
time: 16ms
memory: 74020kb

input:

2171 66
37 62090351 8571
29 49788882 7156
9 74127468 6410
3 14494975 9234
18 98069986 7486
14 69153326 5436
66 89664863 361
25 92260063 3807
9 94370348 890
59 10712232 9445
55 33302118 7245
12 20133542 8125
51 90598109 9513
46 47205380 9746
15 91687141 258
19 45001071 7916
37 13141333 439
3 95698563...

output:

2055482079

result:

wrong answer 1st lines differ - expected: '3069887407', found: '2055482079'