# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
242282 | dantoh000 | 3단 점프 (JOI19_jumps) | C++14 | 570 ms | 124796 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int a[5005];
int st[5005][14];
ll dp[5005][5005];
int q;
int query(int s, int e){
int d = e-s+1;
int bt = 31-__builtin_clz(d);
int ret = max(st[s][bt],st[e-(1<<bt)+1][bt]);
//printf("max from %d to %d is %d\n",s,e,ret);
return ret;
}
int main(){
scanf("%d",&n);
for (int i = 0; i < n; i++){
scanf("%d",&a[i]);
st[i][0] = a[i];
}
for (int k = 1; k < 14; k++){
for (int i = 0; i+(1<<(k-1)) < n; i++){
st[i][k] = max(st[i][k-1],st[i+(1<<(k-1))][k-1]);
}
}
for (int i = 0; i < n; i++){
for (int j = i+2; j < n; j++){
int mid = (i+j)/2;
dp[i][j]= 0ll+a[i]+a[j]+query(i+1,mid);
//printf("<%d,%d>: %d\n",i,j,query(i+1,mid));
}
}
for (int L = 2; L < n; L++){
for (int i = 0; i+L < n; i++){
int j = i+L;
if (i){
dp[i-1][j] = max(dp[i-1][j], dp[i][j]);
}
if (j+1 < n){
dp[i][j+1] = max(dp[i][j+1],dp[i][j]);
}
}
}
scanf("%d",&q);
for (int i = 0; i < q; i++){
int l,r;
scanf("%d%d",&l,&r);
--l, --r;
printf("%lld\n",dp[l][r]);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |