Submission #157223

# Submission time Handle Problem Language Result Execution time Memory
157223 2019-10-10T07:31:34 Z manh9203 스트랩 (JOI14_straps) C++17
95 / 100
249 ms 32252 KB
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#define fi first
#define se second
const int N = 2e3 + 5;
long long n,dp[N][N],rmq[N][20];
pair<long long,long long> rope[N];
long long get(int l,int r){
	int k = log2(r - l + 1);
	return max(rmq[l][k], rmq[r-(1<<k)+1][k]);
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i=1;i<=n;i++) cin >> rope[i].fi >> rope[i].se;
	for(int i=0;i<=n;i++){
		for(int j=1;j<=n;j++){
			dp[i][j] = -1e18;
		}
	}
	sort(rope+1, rope+1+n);
	for(int i=0;i<=n;i++) rmq[i][0] = dp[0][i];
	for(int j=1;(1<<j)<=n;j++){
		for(int i=0;i+(1<<j)-1<=n;j++){
			rmq[i][j] = max(rmq[i][j-1], rmq[i+(1<<(j-1))][j-1]);
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=i;j++){
			dp[i][j] = max(dp[i-1][j], get(j - 1, min(n, j + rope[i].fi - 1)) + rope[i].se);
		}
		for(int j=0;j<=n;j++){
			rmq[j][0] = dp[i][j];
		}
		for(int k=1;(1<<k)<=n;k++){
			for(int j=0;j+(1<<k)-1<=n;j++){
				rmq[j][k] = max(rmq[j][k-1], rmq[j+(1<<(k-1))][k-1]);
			}
		}
	}
	cout << max(dp[n][0], dp[n][1]);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 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 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 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 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Incorrect 3 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 3 ms 888 KB Output is correct
3 Correct 2 ms 764 KB Output is correct
4 Correct 2 ms 888 KB Output is correct
5 Correct 3 ms 888 KB Output is correct
6 Correct 2 ms 888 KB Output is correct
7 Correct 3 ms 888 KB Output is correct
8 Correct 50 ms 12280 KB Output is correct
9 Correct 53 ms 12412 KB Output is correct
10 Correct 53 ms 12280 KB Output is correct
11 Correct 52 ms 12348 KB Output is correct
12 Correct 212 ms 32120 KB Output is correct
13 Correct 214 ms 32252 KB Output is correct
14 Correct 211 ms 32120 KB Output is correct
15 Correct 215 ms 32120 KB Output is correct
16 Correct 207 ms 32120 KB Output is correct
17 Correct 213 ms 32132 KB Output is correct
18 Correct 209 ms 32248 KB Output is correct
19 Correct 205 ms 32120 KB Output is correct
20 Correct 210 ms 32248 KB Output is correct
21 Correct 210 ms 32120 KB Output is correct
22 Correct 211 ms 32132 KB Output is correct
23 Correct 211 ms 32092 KB Output is correct
24 Correct 212 ms 32248 KB Output is correct
25 Correct 222 ms 32248 KB Output is correct
26 Correct 211 ms 32120 KB Output is correct
27 Correct 215 ms 32240 KB Output is correct
28 Correct 208 ms 32248 KB Output is correct
29 Correct 237 ms 32084 KB Output is correct
30 Correct 230 ms 32124 KB Output is correct
31 Correct 238 ms 32248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 964 KB Output is correct
2 Correct 3 ms 888 KB Output is correct
3 Correct 2 ms 888 KB Output is correct
4 Correct 2 ms 764 KB Output is correct
5 Correct 2 ms 888 KB Output is correct
6 Correct 2 ms 892 KB Output is correct
7 Correct 3 ms 892 KB Output is correct
8 Correct 2 ms 888 KB Output is correct
9 Correct 49 ms 12408 KB Output is correct
10 Correct 49 ms 12408 KB Output is correct
11 Correct 49 ms 12280 KB Output is correct
12 Correct 49 ms 12440 KB Output is correct
13 Correct 48 ms 12280 KB Output is correct
14 Correct 48 ms 12280 KB Output is correct
15 Correct 49 ms 12408 KB Output is correct
16 Correct 48 ms 12408 KB Output is correct
17 Correct 218 ms 32120 KB Output is correct
18 Correct 218 ms 32172 KB Output is correct
19 Correct 221 ms 32248 KB Output is correct
20 Correct 230 ms 32248 KB Output is correct
21 Correct 219 ms 32248 KB Output is correct
22 Correct 215 ms 32120 KB Output is correct
23 Correct 217 ms 32092 KB Output is correct
24 Correct 220 ms 32120 KB Output is correct
25 Correct 220 ms 32120 KB Output is correct
26 Correct 214 ms 32120 KB Output is correct
27 Correct 212 ms 32248 KB Output is correct
28 Correct 229 ms 32128 KB Output is correct
29 Correct 216 ms 32220 KB Output is correct
30 Correct 215 ms 32120 KB Output is correct
31 Correct 214 ms 32140 KB Output is correct
32 Correct 210 ms 32128 KB Output is correct
33 Correct 213 ms 32136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 216 ms 32128 KB Output is correct
2 Correct 217 ms 32132 KB Output is correct
3 Correct 211 ms 32248 KB Output is correct
4 Correct 211 ms 32124 KB Output is correct
5 Correct 211 ms 32252 KB Output is correct
6 Correct 220 ms 32132 KB Output is correct
7 Correct 216 ms 32128 KB Output is correct
8 Correct 218 ms 32120 KB Output is correct
9 Correct 224 ms 32120 KB Output is correct
10 Correct 219 ms 32232 KB Output is correct
11 Correct 212 ms 32248 KB Output is correct
12 Correct 218 ms 32120 KB Output is correct
13 Correct 208 ms 32248 KB Output is correct
14 Correct 209 ms 32120 KB Output is correct
15 Correct 208 ms 32140 KB Output is correct
16 Correct 208 ms 32128 KB Output is correct
17 Correct 213 ms 32124 KB Output is correct
18 Correct 215 ms 32120 KB Output is correct
19 Correct 234 ms 32248 KB Output is correct
20 Correct 236 ms 32120 KB Output is correct
21 Correct 232 ms 32132 KB Output is correct
22 Correct 237 ms 32120 KB Output is correct
23 Correct 239 ms 32120 KB Output is correct
24 Correct 249 ms 32248 KB Output is correct
25 Correct 218 ms 32120 KB Output is correct