Submission #1309773

#TimeUsernameProblemLanguageResultExecution timeMemory
1309773Rares송신탑 (IOI22_towers)C++20
23 / 100
4094 ms1564 KiB
#include <bits/stdc++.h>
#include "towers.h"
using namespace std;
/**ifstream fin ("date.in");
ofstream fout ("date.out");
#define cin fin
#define cout fout**/

const int MAXN=1e5+10;

int n,a[MAXN];

void init (int N, vector <int> h){
    n=N;
    for (int i=0;i<n;++i) a[i+1]=h[i];


}

int max_towers (int l, int r, int d){
    l++;
    r++;
    stack <pair <int,int>> st;
    for (int i=l;i<=r;++i){
        if (st.empty ()){
            st.push ({i,0});
        }
        else{
            pair <int,int> p=st.top ();
            if (a[i]+d<=p.second and a[p.first]+d<=p.second){
                st.push ({i,0});
            }
            else{
                if (a[i]>a[p.first]) p.second=max (p.second,a[i]);
                else{
                    p={i,0};
                }
                st.pop ();
                st.push (p);
            }
        }
    }

    return st.size();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...