Submission #58237301


Source Code Expand

// author: sendyuripics
// URL: https://atcoder.jp/contests/abc373/tasks/abc373_f
// created: 2024-09-28 20:00:16
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
#define int long long
using namespace std;
void ts(){cout<<"IAKIOI\n";}
inline int read(){
	int n=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		n=n*10+ch-'0';
		ch=getchar();
	}
	return n*f;
}
int n,W,len;
int w[3005],v[3005];
int dp[3005][3005];
int com[3005],l[3005];
int now;
int get(int j,int i){return l[j]+(i-j)*(now-(i-j));}
void solve(int l,int r,int ql,int qr){
	if(l>r)return;
	int pm=ql;
	int mid=(l+r)/2;
	com[(l+r)/2]=get(pm,mid);
	for(int i=ql+1;i<=qr&&i<mid;i++){
		if(get(i,mid)>=com[mid]){
			pm=i,com[mid]=get(i,mid);
		}
	}
	solve(l,mid-1,ql,pm);solve(mid+1,r,pm,qr);
}
signed main(){
	n=read(),W=read();
	for(int i=1;i<=n;i++){
		w[i]=read(),v[i]=read();
	}
	//你考虑对于一个东西如果
	memset(dp,-0x3f,sizeof(dp));dp[0][0]=0;
	//对于第 (k+1)vi-(k+1)^(k+1)-kvi+k*k
	//delta=vi-2k-1.
	for(int i=1;i<=n;i++){
		for(int j=0;j<=W;j++)dp[i][j]=dp[i-1][j];
		//考虑这个
		for(int j=0;j<w[i];j++){
			len=0;
			now=v[i];
			for(int k=j;k<=W;k+=w[i])l[++len]=dp[i-1][k];
			len=0;
			for(int k=j;k<=W;k+=w[i])com[++len]=0;
			int pt=1;/*
			for(int k=1;k<=len;k++){
				//x=k-1. v[i]-1+l[x].
				//(k+1-x)*(v[i]-k+x-1)-(k-x)*(v[i]-(k-x));
				int cur=pt;
				for(int x=1;x<k;x++){
					if(l[x]+(k-x)*(v[i]-(k-x))>com[k]){
						com[k]=l[x]+(k-x)*(v[i]-(k-x));
						pt=x;
					}
				}
			}*/
			solve(1,len,1,len-1);
			for(int k=j;k<=W;k+=w[i])dp[i][k]=max(dp[i][k],com[(k-j)/w[i]+1]);
		}/*
		for(int j=0;j<=W;j++){
			for(int k=1;k*w[i]<=j;k++){
				//-((k-v[i]/2)^2)+v[i]*v[i]/4
				dp[i][j]=max(dp[i][j],dp[i-1][j-k*w[i]]+k*v[i]-k*k);
			}
		}*/
	}
	int res=0;
	for(int i=0;i<=W;i++)res=max(res,dp[n][i]);
	cout<<res<<"\n";
	return 0;
}
//look at my code
//my code is amazing

Submission Info

Submission Time
Task F - Knapsack with Diminishing Values
User Rideris
Language C++ 20 (gcc 12.2)
Score 550
Code Size 2048 Byte
Status AC
Exec Time 138 ms
Memory 74312 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:59:29: warning: unused variable ‘pt’ [-Wunused-variable]
   59 |                         int pt=1;/*
      |                             ^~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 550 / 550
Status
AC × 3
AC × 58
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 28 ms 74048 KiB
00_sample_02.txt AC 29 ms 74176 KiB
00_sample_03.txt AC 28 ms 73976 KiB
01_random_01.txt AC 136 ms 74172 KiB
01_random_02.txt AC 136 ms 74180 KiB
01_random_03.txt AC 136 ms 74112 KiB
01_random_04.txt AC 137 ms 74180 KiB
01_random_05.txt AC 138 ms 74168 KiB
01_random_06.txt AC 31 ms 74056 KiB
01_random_07.txt AC 111 ms 74084 KiB
01_random_08.txt AC 90 ms 74236 KiB
01_random_09.txt AC 138 ms 74176 KiB
01_random_10.txt AC 33 ms 74212 KiB
01_random_11.txt AC 99 ms 74084 KiB
01_random_12.txt AC 57 ms 74084 KiB
01_random_13.txt AC 108 ms 74160 KiB
01_random_14.txt AC 130 ms 74088 KiB
01_random_15.txt AC 94 ms 74088 KiB
01_random_16.txt AC 35 ms 74056 KiB
01_random_17.txt AC 56 ms 74288 KiB
01_random_18.txt AC 29 ms 74208 KiB
01_random_19.txt AC 130 ms 74088 KiB
01_random_20.txt AC 96 ms 74164 KiB
01_random_21.txt AC 34 ms 74092 KiB
01_random_22.txt AC 39 ms 74084 KiB
01_random_23.txt AC 64 ms 74064 KiB
01_random_24.txt AC 123 ms 74116 KiB
01_random_25.txt AC 37 ms 74120 KiB
01_random_26.txt AC 51 ms 74152 KiB
01_random_27.txt AC 56 ms 74148 KiB
01_random_28.txt AC 56 ms 74160 KiB
01_random_29.txt AC 119 ms 74132 KiB
01_random_30.txt AC 48 ms 74136 KiB
01_random_31.txt AC 39 ms 74048 KiB
01_random_32.txt AC 42 ms 74128 KiB
01_random_33.txt AC 46 ms 74124 KiB
01_random_34.txt AC 119 ms 74312 KiB
01_random_35.txt AC 35 ms 74088 KiB
01_random_36.txt AC 41 ms 74096 KiB
01_random_37.txt AC 73 ms 74176 KiB
01_random_38.txt AC 38 ms 74036 KiB
01_random_39.txt AC 86 ms 74056 KiB
01_random_40.txt AC 44 ms 74092 KiB
01_random_41.txt AC 43 ms 74080 KiB
01_random_42.txt AC 36 ms 74212 KiB
01_random_43.txt AC 70 ms 74068 KiB
01_random_44.txt AC 86 ms 74124 KiB
01_random_45.txt AC 33 ms 74128 KiB
01_random_46.txt AC 50 ms 74164 KiB
01_random_47.txt AC 43 ms 74228 KiB
01_random_48.txt AC 31 ms 74100 KiB
01_random_49.txt AC 86 ms 74112 KiB
01_random_50.txt AC 31 ms 74084 KiB
02_handmade_01.txt AC 85 ms 74172 KiB
02_handmade_02.txt AC 71 ms 74104 KiB
02_handmade_03.txt AC 53 ms 74040 KiB
02_handmade_04.txt AC 55 ms 74164 KiB
02_handmade_05.txt AC 32 ms 74140 KiB