답안 #242285

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

#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)

const int mxN = 5005;
const int lgN = 14;
const int mxQ = 105;

int N, Q, A[mxN];

struct SparseTable {
    int T[mxN][lgN];
    void build() {
        FOR(i,1,N) T[i][0] = i;
        FOR(k,1,lgN-1){
            FOR(i,1,N-(1<<k)+1){
                int p = T[i][k-1], q = T[i+(1<<(k-1))][k-1];
                T[i][k] = (A[p] > A[q] ? p : q);
            }
        }
    }
    int query(int L, int R) {
        if (L > R) return -1e9;
        int k = floor(log2(R-L+1));
        int p = T[L][k], q = T[R-(1<<k)+1][k];
        return max(A[p],A[q]);
    }
} st;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N;
    FOR(i,1,N){
        cin >> A[i];
    }
    st.build();
    cin >> Q;
    FOR(i,1,Q){
        int L, R; cin >> L >> R;
        int ans = 0;
        FOR(x,L,R){
            FOR(y,x+1,R){
                ans = max(ans,A[x]+A[y]+st.query(max(L,x-(y-x)),x-1));
            }
        }
        cout << ans << '\n';
    }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
3 Correct 8 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 7 ms 384 KB Output is correct
7 Correct 7 ms 384 KB Output is correct
8 Correct 7 ms 384 KB Output is correct
9 Correct 9 ms 384 KB Output is correct
10 Correct 7 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
3 Correct 8 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 7 ms 384 KB Output is correct
7 Correct 7 ms 384 KB Output is correct
8 Correct 7 ms 384 KB Output is correct
9 Correct 9 ms 384 KB Output is correct
10 Correct 7 ms 384 KB Output is correct
11 Execution timed out 4093 ms 640 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
3 Correct 8 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 7 ms 384 KB Output is correct
7 Correct 7 ms 384 KB Output is correct
8 Correct 7 ms 384 KB Output is correct
9 Correct 9 ms 384 KB Output is correct
10 Correct 7 ms 384 KB Output is correct
11 Execution timed out 4093 ms 640 KB Time limit exceeded
12 Halted 0 ms 0 KB -