# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
157222 |
2019-10-10T07:22:07 Z |
manh9203 |
스트랩 (JOI14_straps) |
C++17 |
|
245 ms |
32304 KB |
#include<bits/stdc++.h>
using namespace std;
#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] = get(j - 1, min(n, j + rope[i].fi - 1)) + rope[i].se;
dp[i][j] = max(dp[i][j], dp[i-1][j]);
}
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 |
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 |
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 |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 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 |
504 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 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 |
2 ms |
376 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
888 KB |
Output is correct |
3 |
Correct |
2 ms |
888 KB |
Output is correct |
4 |
Correct |
3 ms |
888 KB |
Output is correct |
5 |
Correct |
3 ms |
892 KB |
Output is correct |
6 |
Correct |
2 ms |
888 KB |
Output is correct |
7 |
Correct |
2 ms |
888 KB |
Output is correct |
8 |
Correct |
51 ms |
12408 KB |
Output is correct |
9 |
Correct |
50 ms |
12404 KB |
Output is correct |
10 |
Correct |
49 ms |
12408 KB |
Output is correct |
11 |
Correct |
48 ms |
12280 KB |
Output is correct |
12 |
Correct |
223 ms |
32252 KB |
Output is correct |
13 |
Correct |
220 ms |
32120 KB |
Output is correct |
14 |
Correct |
216 ms |
32248 KB |
Output is correct |
15 |
Correct |
224 ms |
32248 KB |
Output is correct |
16 |
Correct |
214 ms |
32120 KB |
Output is correct |
17 |
Correct |
216 ms |
32220 KB |
Output is correct |
18 |
Correct |
216 ms |
32120 KB |
Output is correct |
19 |
Correct |
213 ms |
32124 KB |
Output is correct |
20 |
Correct |
215 ms |
32248 KB |
Output is correct |
21 |
Correct |
214 ms |
32248 KB |
Output is correct |
22 |
Correct |
212 ms |
32132 KB |
Output is correct |
23 |
Correct |
214 ms |
32220 KB |
Output is correct |
24 |
Correct |
210 ms |
32132 KB |
Output is correct |
25 |
Correct |
210 ms |
32120 KB |
Output is correct |
26 |
Correct |
222 ms |
32128 KB |
Output is correct |
27 |
Correct |
221 ms |
32120 KB |
Output is correct |
28 |
Correct |
213 ms |
32120 KB |
Output is correct |
29 |
Correct |
240 ms |
32164 KB |
Output is correct |
30 |
Correct |
245 ms |
32220 KB |
Output is correct |
31 |
Correct |
243 ms |
32120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
888 KB |
Output is correct |
2 |
Correct |
3 ms |
888 KB |
Output is correct |
3 |
Correct |
3 ms |
888 KB |
Output is correct |
4 |
Correct |
3 ms |
888 KB |
Output is correct |
5 |
Correct |
3 ms |
888 KB |
Output is correct |
6 |
Correct |
3 ms |
888 KB |
Output is correct |
7 |
Correct |
3 ms |
888 KB |
Output is correct |
8 |
Correct |
3 ms |
888 KB |
Output is correct |
9 |
Correct |
52 ms |
12380 KB |
Output is correct |
10 |
Correct |
53 ms |
12400 KB |
Output is correct |
11 |
Correct |
49 ms |
12280 KB |
Output is correct |
12 |
Correct |
50 ms |
12400 KB |
Output is correct |
13 |
Correct |
51 ms |
12440 KB |
Output is correct |
14 |
Correct |
49 ms |
12408 KB |
Output is correct |
15 |
Correct |
49 ms |
12408 KB |
Output is correct |
16 |
Correct |
49 ms |
12408 KB |
Output is correct |
17 |
Correct |
220 ms |
32136 KB |
Output is correct |
18 |
Correct |
222 ms |
32120 KB |
Output is correct |
19 |
Correct |
218 ms |
32168 KB |
Output is correct |
20 |
Correct |
215 ms |
32120 KB |
Output is correct |
21 |
Correct |
217 ms |
32136 KB |
Output is correct |
22 |
Correct |
216 ms |
32248 KB |
Output is correct |
23 |
Correct |
220 ms |
32120 KB |
Output is correct |
24 |
Correct |
230 ms |
32128 KB |
Output is correct |
25 |
Correct |
219 ms |
32128 KB |
Output is correct |
26 |
Correct |
216 ms |
32120 KB |
Output is correct |
27 |
Correct |
221 ms |
32304 KB |
Output is correct |
28 |
Correct |
228 ms |
32132 KB |
Output is correct |
29 |
Correct |
217 ms |
32128 KB |
Output is correct |
30 |
Correct |
214 ms |
32128 KB |
Output is correct |
31 |
Correct |
218 ms |
32120 KB |
Output is correct |
32 |
Correct |
215 ms |
32092 KB |
Output is correct |
33 |
Correct |
214 ms |
32092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
214 ms |
32248 KB |
Output is correct |
2 |
Correct |
214 ms |
32136 KB |
Output is correct |
3 |
Correct |
220 ms |
32140 KB |
Output is correct |
4 |
Correct |
214 ms |
32248 KB |
Output is correct |
5 |
Correct |
213 ms |
32120 KB |
Output is correct |
6 |
Correct |
211 ms |
32048 KB |
Output is correct |
7 |
Correct |
216 ms |
32120 KB |
Output is correct |
8 |
Correct |
211 ms |
32120 KB |
Output is correct |
9 |
Correct |
213 ms |
32160 KB |
Output is correct |
10 |
Correct |
218 ms |
32128 KB |
Output is correct |
11 |
Correct |
225 ms |
32248 KB |
Output is correct |
12 |
Correct |
215 ms |
32156 KB |
Output is correct |
13 |
Correct |
215 ms |
32136 KB |
Output is correct |
14 |
Correct |
210 ms |
32236 KB |
Output is correct |
15 |
Correct |
215 ms |
32128 KB |
Output is correct |
16 |
Correct |
209 ms |
32248 KB |
Output is correct |
17 |
Correct |
218 ms |
32248 KB |
Output is correct |
18 |
Correct |
215 ms |
32132 KB |
Output is correct |
19 |
Correct |
237 ms |
32140 KB |
Output is correct |
20 |
Correct |
245 ms |
32120 KB |
Output is correct |
21 |
Correct |
239 ms |
32120 KB |
Output is correct |
22 |
Correct |
236 ms |
32120 KB |
Output is correct |
23 |
Correct |
241 ms |
32132 KB |
Output is correct |
24 |
Correct |
242 ms |
32120 KB |
Output is correct |
25 |
Correct |
210 ms |
32248 KB |
Output is correct |