답안 #1022944

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1022944 2024-07-14T07:54:50 Z JakobZorz 송신탑 (IOI22_towers) C++17
0 / 100
4000 ms 10556 KB
#include"towers.h"
#include<vector>
#include<iostream>
using namespace std;

int n;
vector<int>arr;
vector<int>thres;
vector<int>prv,nxt;
vector<vector<int>>rmq;

void init_prev(){
    prv.resize(n);
    vector<int>s;
    for(int i=0;i<n;i++){
        while(s.size()&&arr[s.back()]>arr[i])
            s.pop_back();
        if(s.empty())
            prv[i]=-1;
        else
            prv[i]=s.back();
        s.push_back(i);
    }
}

void init_nxt(){
    nxt.resize(n);
    vector<int>s;
    for(int i=n-1;i>=0;i--){
        while(s.size()&&arr[s.back()]>arr[i])
            s.pop_back();
        if(s.empty())
            nxt[i]=-1;
        else
            nxt[i]=s.back();
        s.push_back(i);
    }
}

void init_rmq(){
    rmq=vector<vector<int>>(20,vector<int>(n));
    rmq[0]=arr;
    for(int p=1;p<20;p++){
        for(int i=0;i+(1<<p)<=n;i++){
            rmq[p][i]=max(rmq[p-1][i],rmq[p-1][i+(1<<(p-1))]);
        }
    }
}

int get_max(int l,int r){
    int pw2=2;
    int p=0;
    while(pw2<r-l){
        pw2*=2;
        p++;
    }
    pw2/=2;
    return max(rmq[p][l],rmq[p][r-pw2]);
}

void init_thres(){
    thres.resize(n);
    for(int i=0;i<n;i++){
        int mn=2e9;
        
        if(prv[i]!=-1){
            int mx1=get_max(prv[i],i);
            mn=min(mn,mx1);
        }
        
        if(nxt[i]!=-1){
            int mx2=get_max(i,nxt[i]);
            mn=min(mn,mx2);
        }
        
        thres[i]=mn-arr[i];
    }
}

void init(int N,vector<int>H){
    arr=H;
    n=(int)arr.size();
    init_prev();
    init_nxt();
    init_rmq();
    init_thres();
}

int max_towers(int L,int R,int D){
    int first=-1,last=-1;
    int res=0;
    for(int i=L;i<=R;i++){
        if(thres[i]>=D){
            res++;
            if(first==-1)
                first=i;
            last=i;
        }
    }
    if(first==-1){
        first=L;
        for(int i=L;i<=R;i++)
            if(arr[i]<arr[first])
                first=i;
        res=1;
    }
    
    int mx=0;
    for(int i=first;i>=L;i--){
        if(max(arr[i],arr[first])+D<=mx){
            res++;
            break;
        }
        mx=max(mx,arr[i]);
    }
    
    mx=0;
    for(int i=last;i<=R;i++){
        if(max(arr[i],arr[last])+D<=mx){
            res++;
            break;
        }
        mx=max(mx,arr[i]);
    }
    
    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4014 ms 6420 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 432 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Incorrect 0 ms 600 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 432 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Incorrect 0 ms 600 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4034 ms 10452 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1593 ms 2840 KB Output is correct
2 Execution timed out 4016 ms 10556 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 432 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Incorrect 0 ms 600 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4014 ms 6420 KB Time limit exceeded
2 Halted 0 ms 0 KB -