답안 #157202

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
157202 2019-10-10T04:09:43 Z puppies_and_rainbows 스트랩 (JOI14_straps) C++14
100 / 100
86 ms 63300 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

int dp[2005][2005];
pair<int, int> a[2005];
int maxdp[2005][2005];

signed main()
{
	int n;
	cin>>n;
	for(int i=1; i<=n; i++)
	{
		cin>>a[i].first>>a[i].second;
		a[i].first--;
	}
	sort(a+1, a+n+1);
	for(int i=1; i<=n/2; i++)
	{
		swap(a[i], a[n+1-i]);
	}
	for(int i=0; i<=n+1; i++)
	{
		dp[0][i]=-100000000000;
	}
	for(int i=n+1; i>1; i--)
	{
		maxdp[0][i]=-100000000000;
	}
	dp[0][1]=0;
	for(int i=1; i<=n; i++)
	{
		for(int j=0; j<=n+1; j++)
		{
			dp[i][j]=dp[i-1][j];
		}
		for(int j=a[i].first+1; j<=n; j++)
		{
			dp[i][j]=max(dp[i][j], dp[i-1][j-a[i].first]+a[i].second);
		}
		dp[i][0]=max(dp[i-1][0], maxdp[i-1][1]+a[i].second);
		dp[i][n]=max(dp[i][n], maxdp[i-1][max(1ll, n-a[i].first)]+a[i].second);
		maxdp[i][n+1]=dp[i][n+1];
		for(int j=n; j>=1; j--)
		{
			maxdp[i][j]=max(maxdp[i][j+1], dp[i][j]);
		}
	}
	// for(int i=1; i<=n; i++)
	// {
	// 	for(int j=1; j<=n; j++)
	// 	{
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	int ans=0;
	for(int i=0; i<=n; i++)
	{
		ans=max(ans, dp[n][i]);
	}
	cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 504 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 476 KB Output is correct
2 Correct 3 ms 1276 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 3 ms 1276 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 3 ms 1272 KB Output is correct
8 Correct 26 ms 24056 KB Output is correct
9 Correct 26 ms 24056 KB Output is correct
10 Correct 26 ms 24056 KB Output is correct
11 Correct 26 ms 24056 KB Output is correct
12 Correct 72 ms 63196 KB Output is correct
13 Correct 74 ms 63204 KB Output is correct
14 Correct 73 ms 63096 KB Output is correct
15 Correct 73 ms 63128 KB Output is correct
16 Correct 73 ms 63124 KB Output is correct
17 Correct 73 ms 63096 KB Output is correct
18 Correct 73 ms 63224 KB Output is correct
19 Correct 73 ms 63224 KB Output is correct
20 Correct 73 ms 63096 KB Output is correct
21 Correct 73 ms 63224 KB Output is correct
22 Correct 72 ms 63224 KB Output is correct
23 Correct 72 ms 63224 KB Output is correct
24 Correct 73 ms 63224 KB Output is correct
25 Correct 72 ms 63224 KB Output is correct
26 Correct 73 ms 63224 KB Output is correct
27 Correct 73 ms 63096 KB Output is correct
28 Correct 73 ms 63224 KB Output is correct
29 Correct 82 ms 63224 KB Output is correct
30 Correct 71 ms 63096 KB Output is correct
31 Correct 71 ms 63224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1272 KB Output is correct
2 Correct 3 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 3 ms 1276 KB Output is correct
5 Correct 3 ms 1272 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 3 ms 1272 KB Output is correct
8 Correct 3 ms 1272 KB Output is correct
9 Correct 27 ms 24092 KB Output is correct
10 Correct 28 ms 24056 KB Output is correct
11 Correct 26 ms 24056 KB Output is correct
12 Correct 26 ms 24056 KB Output is correct
13 Correct 44 ms 24184 KB Output is correct
14 Correct 27 ms 24056 KB Output is correct
15 Correct 26 ms 24056 KB Output is correct
16 Correct 26 ms 24056 KB Output is correct
17 Correct 73 ms 63300 KB Output is correct
18 Correct 73 ms 63224 KB Output is correct
19 Correct 74 ms 63224 KB Output is correct
20 Correct 73 ms 63224 KB Output is correct
21 Correct 73 ms 63096 KB Output is correct
22 Correct 73 ms 63096 KB Output is correct
23 Correct 74 ms 63096 KB Output is correct
24 Correct 74 ms 63096 KB Output is correct
25 Correct 73 ms 63096 KB Output is correct
26 Correct 74 ms 63224 KB Output is correct
27 Correct 74 ms 63096 KB Output is correct
28 Correct 81 ms 63224 KB Output is correct
29 Correct 83 ms 63096 KB Output is correct
30 Correct 74 ms 63224 KB Output is correct
31 Correct 83 ms 63096 KB Output is correct
32 Correct 76 ms 63224 KB Output is correct
33 Correct 75 ms 63200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 63096 KB Output is correct
2 Correct 78 ms 63280 KB Output is correct
3 Correct 80 ms 63224 KB Output is correct
4 Correct 73 ms 63224 KB Output is correct
5 Correct 73 ms 63224 KB Output is correct
6 Correct 83 ms 63200 KB Output is correct
7 Correct 73 ms 63096 KB Output is correct
8 Correct 73 ms 63188 KB Output is correct
9 Correct 73 ms 63096 KB Output is correct
10 Correct 73 ms 63172 KB Output is correct
11 Correct 73 ms 63196 KB Output is correct
12 Correct 73 ms 63224 KB Output is correct
13 Correct 73 ms 63196 KB Output is correct
14 Correct 73 ms 63224 KB Output is correct
15 Correct 74 ms 63224 KB Output is correct
16 Correct 74 ms 63168 KB Output is correct
17 Correct 73 ms 63224 KB Output is correct
18 Correct 75 ms 63224 KB Output is correct
19 Correct 71 ms 63224 KB Output is correct
20 Correct 71 ms 63224 KB Output is correct
21 Correct 73 ms 63120 KB Output is correct
22 Correct 72 ms 63096 KB Output is correct
23 Correct 81 ms 63224 KB Output is correct
24 Correct 86 ms 63100 KB Output is correct
25 Correct 74 ms 63196 KB Output is correct