답안 #515520

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
515520 2022-01-19T08:23:25 Z 79brue 3단 점프 (JOI19_jumps) C++14
5 / 100
4000 ms 4824 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<20; 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);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 8 ms 320 KB Output is correct
3 Correct 6 ms 204 KB Output is correct
4 Correct 6 ms 312 KB Output is correct
5 Correct 7 ms 316 KB Output is correct
6 Correct 7 ms 316 KB Output is correct
7 Correct 8 ms 204 KB Output is correct
8 Correct 8 ms 204 KB Output is correct
9 Correct 10 ms 316 KB Output is correct
10 Correct 6 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 8 ms 320 KB Output is correct
3 Correct 6 ms 204 KB Output is correct
4 Correct 6 ms 312 KB Output is correct
5 Correct 7 ms 316 KB Output is correct
6 Correct 7 ms 316 KB Output is correct
7 Correct 8 ms 204 KB Output is correct
8 Correct 8 ms 204 KB Output is correct
9 Correct 10 ms 316 KB Output is correct
10 Correct 6 ms 204 KB Output is correct
11 Execution timed out 4050 ms 332 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4057 ms 4824 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 8 ms 320 KB Output is correct
3 Correct 6 ms 204 KB Output is correct
4 Correct 6 ms 312 KB Output is correct
5 Correct 7 ms 316 KB Output is correct
6 Correct 7 ms 316 KB Output is correct
7 Correct 8 ms 204 KB Output is correct
8 Correct 8 ms 204 KB Output is correct
9 Correct 10 ms 316 KB Output is correct
10 Correct 6 ms 204 KB Output is correct
11 Execution timed out 4050 ms 332 KB Time limit exceeded
12 Halted 0 ms 0 KB -