답안 #859272

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
859272 2023-10-10T03:06:14 Z nnhzzz 3단 점프 (JOI19_jumps) C++14
32 / 100
4000 ms 3452 KB
#include<bits/stdc++.h>

using namespace std;

#define task "test"
#define REP(i,a,b) for(int i = (a); i<=(b); ++i)
#define REPD(i,a,b) for(int i = (a); i>=(b); --i)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int)(x).size()
#define BIT(x,i) ((x>>i)&1LL)
#define MASK(i) (1LL<<i)
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int,int>
//-----------------------------------------------------------------------//
const int oo = 1e9,LOG = 19,MAXN = 5e5+7,N = 1e2+3;
const int MOD = 1e9+7,MOD1 = 1e9+207,MOD2 = 1e9+407,MOD3 = 998244353;
//-----------------------------------------------------------------------//
template<typename T> bool mini(T &a, T b){if(a>b){a=b;return true;} return false;}
template<typename T> bool maxi(T &a, T b){if(a<b){a=b;return true;} return false;}

int a[MAXN];
int n,q;

void sub3(){
    while(q--){
        int res = 0,l,r; cin >> l >> r;
        stack<int> st; vi dp(n*2+8,0);
        REP(i,l,r){
            while(SZ(st)!=0 && a[st.top()]<a[i]){
                maxi(dp[2*i-st.top()],a[i]+a[st.top()]);
                st.pop();
            }
            if(SZ(st)!=0) maxi(dp[2*i-st.top()],a[i]+a[st.top()]);
            st.push(i);
        }
        REP(i,l,r){
            maxi(dp[i],dp[i-1]);
            maxi(res,dp[i]+a[i]);
        }
        cout << res << "\n";
    }
}

void sub4(){
}

void solve(){
    cin >> n;
    REP(i,1,n){
        cin >> a[i];
    }
    cin >> q;
        sub3(); return;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if(fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    solve();
    return 0;
}

Compilation message

jumps.cpp: In function 'int main()':
jumps.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
jumps.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Execution timed out 4059 ms 2476 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 2652 KB Output is correct
2 Correct 23 ms 2696 KB Output is correct
3 Correct 24 ms 3452 KB Output is correct
4 Correct 18 ms 2652 KB Output is correct
5 Correct 19 ms 2908 KB Output is correct
6 Correct 16 ms 2652 KB Output is correct
7 Correct 15 ms 2612 KB Output is correct
8 Correct 15 ms 2704 KB Output is correct
9 Correct 17 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Execution timed out 4059 ms 2476 KB Time limit exceeded
12 Halted 0 ms 0 KB -