답안 #242318

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
242318 2020-06-27T08:46:20 Z tqbfjotld 3단 점프 (JOI19_jumps) C++14
19 / 100
4000 ms 202028 KB
#include <bits/stdc++.h>
using namespace std;

long long arr[500005];
long long memo[5005][5005];

struct node{
    int s,e;
    long long v;
    node *l,*r;
    node(int _s, int _e){
    s = _s;
    e = _e;
    if (s==e) v = arr[s];
    else{
        l = new node(s,(s+e)/2);
        r = new node((s+e)/2+1,e);
        v = max(l->v,r->v);
    }
    }
    long long qu(int a, int b){
        //printf("called node %d %d\n",s,e);
        if (b<a) return -99999999999999LL;
        if (a<=s && e<=b) return v;
        if (b<=(s+e)/2) return l->qu(a,b);
        if (a>(s+e)/2) return r->qu(a,b);
        return max(l->qu(a,b),r->qu(a,b));
    }
}*root;

int main(){
    int n,q;
    scanf("%d",&n);
    for (int x = 0; x<n; x++){
        scanf("%lld",&arr[x]);
    }
    scanf("%d",&q);
    if (false){
        for (int x = 0; x<q; x++){
            int l,r;
            scanf("%d%d",&l,&r);
            l--;r--;
            long long ans = 0;
            for (int a = l; a<=r; a++){
                for (int c = a+2; c<=r; c++){
                    for (int b = a+1; c-b>=b-a; b++){
                        ans = max(ans,arr[a]+arr[b]+arr[c]);
                    }
                }
            }
            printf("%lld\n",ans);
        }
    }
    else{
        root = new node(0,n);
        //printf("%lld\n",root->qu(1,2));
        for (int x = 0; x<n; x++){
            for (int y = 0; y<n; y++){
                memo[x][y] = root->qu(x+1,(x+y)/2) + arr[x]+arr[y];
                //printf("jump %d %d is %lld\n",x,y,memo[x][y]);
            }
        }
        for (int x = 0; x<n; x++){
            for (int y = 1; y<n; y++){
                memo[x][y] = max(memo[x][y],memo[x][y-1]);
            }
        }
        for (int x = n-2; x>=0; x--){
            for (int y = 0; y<n; y++){
                memo[x][y] = max(memo[x][y],memo[x+1][y]);
            }
        }
        for (int x = 0; x<q; x++){
            int l,r;
            scanf("%d%d",&l,&r);
            l--;r--;
            printf("%lld\n",memo[l][r]);
        }
    }
}

Compilation message

jumps.cpp: In function 'int main()':
jumps.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
jumps.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&arr[x]);
         ~~~~~^~~~~~~~~~~~~~~~
jumps.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&q);
     ~~~~~^~~~~~~~~
jumps.cpp:41:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d",&l,&r);
             ~~~~~^~~~~~~~~~~~~~
jumps.cpp:75:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d",&l,&r);
             ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 768 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 5 ms 768 KB Output is correct
5 Correct 5 ms 768 KB Output is correct
6 Correct 5 ms 768 KB Output is correct
7 Correct 5 ms 768 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 5 ms 948 KB Output is correct
10 Correct 5 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 768 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 5 ms 768 KB Output is correct
5 Correct 5 ms 768 KB Output is correct
6 Correct 5 ms 768 KB Output is correct
7 Correct 5 ms 768 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 5 ms 948 KB Output is correct
10 Correct 5 ms 768 KB Output is correct
11 Correct 1457 ms 202028 KB Output is correct
12 Correct 1415 ms 201632 KB Output is correct
13 Correct 1447 ms 201908 KB Output is correct
14 Correct 1428 ms 201840 KB Output is correct
15 Correct 1433 ms 201848 KB Output is correct
16 Correct 1437 ms 201128 KB Output is correct
17 Correct 1435 ms 201160 KB Output is correct
18 Correct 1426 ms 201112 KB Output is correct
19 Correct 1414 ms 201760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4054 ms 27936 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 768 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 5 ms 768 KB Output is correct
5 Correct 5 ms 768 KB Output is correct
6 Correct 5 ms 768 KB Output is correct
7 Correct 5 ms 768 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 5 ms 948 KB Output is correct
10 Correct 5 ms 768 KB Output is correct
11 Correct 1457 ms 202028 KB Output is correct
12 Correct 1415 ms 201632 KB Output is correct
13 Correct 1447 ms 201908 KB Output is correct
14 Correct 1428 ms 201840 KB Output is correct
15 Correct 1433 ms 201848 KB Output is correct
16 Correct 1437 ms 201128 KB Output is correct
17 Correct 1435 ms 201160 KB Output is correct
18 Correct 1426 ms 201112 KB Output is correct
19 Correct 1414 ms 201760 KB Output is correct
20 Execution timed out 4054 ms 27936 KB Time limit exceeded
21 Halted 0 ms 0 KB -