답안 #242304

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
242304 2020-06-27T08:36:04 Z tqbfjotld 3단 점프 (JOI19_jumps) C++14
5 / 100
4000 ms 204664 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){
        if (b<a) return -99999999999999LL;
        if (a<=s && e<=b) return v;
        if (a<=(s+e)/2) return l->qu(a,b);
        if (b>(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 (n<=100 && q<=100){
        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);
        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];
            }
        }
        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-1; 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:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
jumps.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&arr[x]);
         ~~~~~^~~~~~~~~~~~~~~~
jumps.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&q);
     ~~~~~^~~~~~~~~
jumps.cpp:40: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:72: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 5 ms 384 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 6 ms 256 KB Output is correct
7 Correct 6 ms 256 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 6 ms 256 KB Output is correct
7 Correct 6 ms 256 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Incorrect 897 ms 204664 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4072 ms 36916 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 6 ms 256 KB Output is correct
7 Correct 6 ms 256 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Incorrect 897 ms 204664 KB Output isn't correct
12 Halted 0 ms 0 KB -