답안 #651425

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
651425 2022-10-18T18:05:58 Z Lobo 송신탑 (IOI22_towers) C++17
0 / 100
4000 ms 5992 KB
#include "towers.h"
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fr first
#define sc second

const int maxn = 1e5+10;
const int inf = 1e9+10;

int n, a[maxn], atv[maxn];
pair<int,int> trmn[4*maxn], trmx[4*maxn];

void att(int no, int l, int r, int pos, int val) {
    if(l > pos || r < pos) return;
    if(l == r) {
        trmn[no] = mp(val,pos);
        trmx[no] = mp(val,pos);
        return;
    }
    int f1=2*no,f2=2*no+1,mid=(l+r)/2;
    att(f1,l,mid,pos,val);
    att(f2,mid+1,r,pos,val);
    trmn[no] = min(trmn[f1],trmn[f2]);
    trmx[no] = max(trmx[f1],trmx[f2]);
}
pair<int,int> qrmn(int no, int l, int r, int L, int R) {
    if(l > R || r < L) return mp(inf,0);
    if(l >= L && r <= R) return trmn[no];
    int f1=2*no,f2=2*no+1,mid=(l+r)/2;
    return min(qrmn(f1,l,mid,L,R),qrmn(f2,mid+1,r,L,R));
}
pair<int,int> qrmx(int no, int l, int r, int L, int R) {
    if(l > R || r < L) return mp(-inf,0);
    if(l >= L && r <= R) return trmx[no];
    int f1=2*no,f2=2*no+1,mid=(l+r)/2;
    return max(qrmx(f1,l,mid,L,R),qrmx(f2,mid+1,r,L,R));
}

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

int sol(int l, int r, int d) {
    int i = qrmx(1,0,n-1,l,r).sc;
    int ans = 0;
    if(i != l && qrmn(1,0,n-1,l,i-1).fr <= a[i]-d) {
        int ansl = sol(l,i-1,d);
        ans+= max(ansl,1);
        if(ansl == 0) {
            ans+= 1;
            atv[qrmn(1,0,n-1,l,i-1).sc] = 1;
        }
    }
    if(i != r && qrmn(1,0,n-1,i+1,r).fr <= a[i]-d) {
        int ansr = sol(i+1,r,d);
        ans+= max(ansr,1);
        if(ansr == 0) {
            ans+= 1;
            atv[qrmn(1,0,n-1,i+1,r).sc] = 1;
        }
    }
    // if(i != l && qrmn(1,0,n-1,l,i-1).fr <= a[i]-d) ans+= max(1,sol(l,i-1,d));
    // if(i != r && qrmn(1,0,n-1,i+1,r).fr <= a[i]-d) ans+= max(1,sol(i+1,r,d));
    // cout << l << " " << r << " " << d << " " << ans << endl;
    return ans;
}

int max_towers(int L, int R, int D) {
    return max(1,sol(L,R,D));
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4090 ms 5992 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 336 KB 1st lines differ - on the 1st token, expected: '13', found: '26'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 336 KB 1st lines differ - on the 1st token, expected: '13', found: '26'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4014 ms 5688 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4083 ms 1656 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 336 KB 1st lines differ - on the 1st token, expected: '13', found: '26'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4090 ms 5992 KB Time limit exceeded
2 Halted 0 ms 0 KB -