답안 #808648

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
808648 2023-08-05T08:34:41 Z oscar1f 3단 점프 (JOI19_jumps) C++17
27 / 100
42 ms 10244 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long

const int MAX_VAL=500*1000+5,INFINI=1000*1000*1000;
int nbVal,nbReq,debReq,finReq,idReq,posRep,debInter,midInter,ancPos;
int val[MAX_VAL];
int maxi[MAX_VAL];
int rep[MAX_VAL];
vector<int> enCours;
vector<pair<int,int>> paireInter;
vector<tuple<int,int,int>> listeReq;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>nbVal;
    for (int i=1;i<=nbVal;i++) {
        cin>>val[i];
    }
    enCours.push_back(1);
    for (int i=2;i<=nbVal;i++) {
        while (!enCours.empty() and val[enCours.back()]<=val[i]) {
            if (nbVal-i>=i-enCours.back()) {
                paireInter.push_back({enCours.back(),i});
            }
            enCours.pop_back();
        } 
        if (!enCours.empty()) {
            if (nbVal-i>=i-enCours.back()) {
                paireInter.push_back({enCours.back(),i});
            }
        }
        enCours.push_back(i);
    }
    sort(paireInter.begin(),paireInter.end());
    /*for (auto i:paireInter) {
        cout<<i.first<<" "<<i.second<<endl;
    }
    cout<<endl;*/
    cin>>nbReq;
    for (int ireq=1;ireq<=nbReq;ireq++) {
        cin>>debReq>>finReq;
        listeReq.push_back(make_tuple(debReq,finReq,ireq));
    }
    sort(listeReq.begin(),listeReq.end());
    for (auto r:listeReq) {
        debReq=get<0>(r);
        finReq=get<1>(r);
        idReq=get<2>(r);
        maxi[finReq+1]=0;
        for (int i=finReq;i>=debReq;i--) {
            maxi[i]=max(maxi[i+1],val[i]);
        }
        for (int i=0;i<(int)paireInter.size();i++) {
            debInter=paireInter[i].first;
            midInter=paireInter[i].second;
            if (debInter>=debReq and 2*midInter-debInter<=finReq and rep[idReq]<val[debInter]+val[midInter]+maxi[2*midInter-debInter]) {
                rep[idReq]=val[debInter]+val[midInter]+maxi[2*midInter-debInter];
                posRep=i;
            }
        }
        if (posRep<ancPos) {
            exit(1);
        } 
        ancPos=posRep;
        //cout<<posRep<<" ";
    }
    //cout<<endl;
    for (int ireq=1;ireq<=nbReq;ireq++) {
        cout<<rep[ireq]<<"\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution failed because the return code was nonzero
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution failed because the return code was nonzero
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 10184 KB Output is correct
2 Correct 23 ms 6712 KB Output is correct
3 Correct 24 ms 10244 KB Output is correct
4 Correct 41 ms 10148 KB Output is correct
5 Correct 40 ms 10236 KB Output is correct
6 Correct 38 ms 10204 KB Output is correct
7 Correct 39 ms 10192 KB Output is correct
8 Correct 36 ms 10184 KB Output is correct
9 Correct 40 ms 10200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution failed because the return code was nonzero
3 Halted 0 ms 0 KB -