Submission #515519

# Submission time Handle Problem Language Result Execution time Memory
515519 2022-01-19T08:23:08 Z 79brue Triple Jump (JOI19_jumps) C++14
5 / 100
4000 ms 3368 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, q;
int arr[500002];
int DP[5002][5002];
int DPmax[5002][5002];

void solveSmall(){
    for(int i=1; i<=n; i++){
        DPmax[i][i] = arr[i];
        for(int j=i+1; j<=n; j++){
            DPmax[i][j] = max(DPmax[i][j-1], arr[j]);
        }
    }
    for(int i=1; i<=n-2; i++) DP[i][i+2] = arr[i] + arr[i+1] + arr[i+2];
    for(int d=3; d<n; d++){
        for(int i=1; i+d<=n; i++){
            int j = i+d;
            DP[i][j] = max({DP[i][j-1], DP[i+1][j], arr[i] + arr[j] + DPmax[i+1][(i+j)/2]});
        }
    }

    scanf("%d", &q);
    while(q--){
        int l, r;
        scanf("%d %d", &l, &r);
        printf("%d\n", DP[l][r]);
    }
    exit(0);
}

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%d", &arr[i]);

//    if(n <= 5000) solveSmall();

    scanf("%d", &q);
    while(q--){
        int l, r;
        scanf("%d %d", &l, &r);

        int ans = 0;
        for(int a=l; a<=r-2; a++){
            vector<pair<int, int> > vec;
            for(int j=a+1; j<=r; j++) vec.push_back(make_pair(arr[j], j));
            sort(vec.rbegin(), vec.rend());
            for(int j=0; j<(int)vec.size(); j++){
                for(int k=a+1; k<=r; k++){
                    if(vec[j].second == k) continue;
                    int b = min(vec[j].second, k);
                    int c = max(vec[j].second, k);
                    if(b-a <= c-b) ans = max(ans, arr[a]+arr[b]+arr[c]);
                }
            }
        }
        printf("%d\n", ans);
    }
}

Compilation message

jumps.cpp: In function 'void solveSmall()':
jumps.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
jumps.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         scanf("%d %d", &l, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~~
jumps.cpp: In function 'int main()':
jumps.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
jumps.cpp:38:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     for(int i=1; i<=n; i++) scanf("%d", &arr[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~
jumps.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
jumps.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         scanf("%d %d", &l, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 12 ms 324 KB Output is correct
3 Correct 10 ms 320 KB Output is correct
4 Correct 10 ms 312 KB Output is correct
5 Correct 10 ms 300 KB Output is correct
6 Correct 12 ms 300 KB Output is correct
7 Correct 13 ms 316 KB Output is correct
8 Correct 12 ms 320 KB Output is correct
9 Correct 19 ms 204 KB Output is correct
10 Correct 10 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 12 ms 324 KB Output is correct
3 Correct 10 ms 320 KB Output is correct
4 Correct 10 ms 312 KB Output is correct
5 Correct 10 ms 300 KB Output is correct
6 Correct 12 ms 300 KB Output is correct
7 Correct 13 ms 316 KB Output is correct
8 Correct 12 ms 320 KB Output is correct
9 Correct 19 ms 204 KB Output is correct
10 Correct 10 ms 204 KB Output is correct
11 Execution timed out 4037 ms 332 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4022 ms 3368 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 12 ms 324 KB Output is correct
3 Correct 10 ms 320 KB Output is correct
4 Correct 10 ms 312 KB Output is correct
5 Correct 10 ms 300 KB Output is correct
6 Correct 12 ms 300 KB Output is correct
7 Correct 13 ms 316 KB Output is correct
8 Correct 12 ms 320 KB Output is correct
9 Correct 19 ms 204 KB Output is correct
10 Correct 10 ms 204 KB Output is correct
11 Execution timed out 4037 ms 332 KB Time limit exceeded
12 Halted 0 ms 0 KB -