답안 #1009531

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1009531 2024-06-27T15:32:11 Z bachhoangxuan 송신탑 (IOI22_towers) C++17
0 / 100
4000 ms 9684 KB
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
const int maxl = 20;

int N,D=-1;
vector<int> H;
int nxt[maxn][maxl],lt[maxn],rt[maxn];

void build(int _D){
    vector<int> v;D=_D;
    for(int i=0;i<=N;i++) lt[i]=rt[i]=-1,nxt[i][0]=N;
    for(int i=0;i<N;i++){
        while(!v.empty() && H[v.back()]>H[i]) v.pop_back();
        int l=0,r=(int)v.size()-1;
        while(l<=r){
            int mid=(l+r)>>1;
            if(H[v[mid]]<=H[i]-D) lt[i]=v[mid],l=mid+1;
            else r=mid-1;
        }
        v.push_back(i);
    }
    v.clear();
    for(int i=N-1;i>=0;i--){
        while(!v.empty() && H[v.back()]>H[i]) v.pop_back();
        int l=0,r=(int)v.size()-1;
        while(l<=r){
            int mid=(l+r)>>1;
            if(H[v[mid]]<=H[i]-D) rt[i]=v[mid],l=mid+1;
            else r=mid-1;
        }
        v.push_back(i);
    }
    for(int i=0;i<N;i++){
        if(lt[i]==-1 || rt[i]==-1) continue;
        nxt[lt[i]][0]=min(nxt[lt[i]][0],rt[i]);
    }
    for(int i=0;i<N;i++) nxt[i][0]=min(nxt[i][0],nxt[i+1][0]);
    for(int i=1;i<18;i++) for(int j=0;j<=N;j++) nxt[j][i]=nxt[nxt[j][i-1]][i-1];
}

void init(int _N, std::vector<int> _H){
    N=_N;H=_H;
}

int max_towers(int L, int R, int _D){
    if(_D!=D) build(_D);
    int cnt=1;
    for(int i=17;i>=0;i--){
        if(nxt[L][i]<=R) L=nxt[L][i],cnt+=(1<<i);
    }
    return cnt;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4038 ms 7652 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB 1st lines differ - on the 1st token, expected: '13', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB 1st lines differ - on the 1st token, expected: '13', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 506 ms 9684 KB 1st lines differ - on the 1st token, expected: '11903', found: '49'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4005 ms 4696 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB 1st lines differ - on the 1st token, expected: '13', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4038 ms 7652 KB Time limit exceeded
2 Halted 0 ms 0 KB -