Submission #1179511

#TimeUsernameProblemLanguageResultExecution timeMemory
1179511gygRadio Towers (IOI22_towers)C++20
11 / 100
4099 ms2284 KiB
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
#define arr array 
#define vec vector
const int N = 1e5 + 5;

int n;
arr<int, N> h;

void init(int _n, vec<int> _h) {
    n = _n;
    for (int i = 1; i <= n; i++) h[i] = _h[i - 1];
}

int s, f, d;

arr<int, N> lf, rg;
void prp_cmp() {
    for (int i = 1; i <= n; i++) {
        lf[i] = 1, rg[i] = n;
        for (int j = i - 1; j >= 1; j--) {
            if (h[j] >= h[i] + d) {
                lf[i] = j;
                break;
            }
        }
        for (int j = i + 1; j <= n; j++) {
            if (h[j] >= h[i] + d) {
                rg[i] = j;
                break;
            }
        }
    }

    // for (int i = 1; i <= n; i++) {
    //     cout << i << ": " << lf[i] << " " << rg[i] << '\n';
    // }
}

arr<int, N> dp;
void dp_cmp() {
    for (int i = s; i <= f; i++) {
        dp[i] = 1;
        for (int j = s; j <= i - 1; j++) {
            if (j < lf[i] && i > rg[j]) {
                dp[i] = max(dp[i], dp[j] + 1);
            }
        }
    }
}

int max_towers(int _s, int _f, int _d) {
    s = _s + 1, f = _f + 1, d = _d;

    prp_cmp();
    dp_cmp();

    int ans = 0;
    for (int i = s; i <= f; i++) ans = max(ans, dp[i]);
    return ans;
}
#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...