Submission #732026

# Submission time Handle Problem Language Result Execution time Memory
732026 2023-04-28T08:59:17 Z alextodoran Radio Towers (IOI22_towers) C++17
0 / 100
4000 ms 14636 KB
/**
 _  _   __  _ _ _  _  _ _
 |a  ||t  ||o    d | |o  |
| __    _| | _ | __|  _ |
| __ |/_  | __  /__\ / _\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 100000;
const int E_MAX = 17;

int N;
int H[N_MAX];

int rmx[N_MAX][E_MAX];
int rmn[N_MAX][E_MAX];

int fmx (int i, int j) {
    return (H[i] > H[j] ? i : j);
}
int fmn (int i, int j) {
    return (H[i] < H[j] ? i : j);
}

void init (int _N, vector <int> _H) {
    N = _N;
    for (int i = 0; i < N; i++) {
        H[i] = _H[i];
        rmx[i][0] = rmn[i][0] = i;
    }
    for (int e = 1; e < E_MAX; e++) {
        for (int i = 0; i + (1 << e) - 1 < N; i++) {
            rmx[i][e] = fmx(rmx[i][e - 1], rmx[i + (1 << (e - 1))][e - 1]);
            rmn[i][e] = fmn(rmn[i][e - 1], rmn[i + (1 << (e - 1))][e - 1]);
        }
    }
}

int getmx (int l, int r) {
    int e = 31 - __builtin_clz(r - l + 1);
    return max(rmx[l][e], rmx[r - (1 << e) + 1][e]);
}
int getmn (int l, int r) {
    int e = 31 - __builtin_clz(r - l + 1);
    return min(rmn[l][e], rmn[r - (1 << e) + 1][e]);
}

int max_towers (int L, int R, int D) {
    if (L > R) {
        return 0;
    }
    if (L == R) {
        return 1;
    }
    int K = getmx(L, R);
    int mxtL = max_towers(L, K - 1, D);
    int mxtR = max_towers(K + 1, R, D);
    return (H[getmn(L, K)] <= H[K] - D && H[getmn(K, R)] <= H[K] - D ? mxtL + mxtR : max(mxtL, mxtR));
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4059 ms 12520 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 592 KB 1st lines differ - on the 1st token, expected: '292', found: '284'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 592 KB 1st lines differ - on the 1st token, expected: '292', found: '284'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4046 ms 14636 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4067 ms 3716 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 592 KB 1st lines differ - on the 1st token, expected: '292', found: '284'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4059 ms 12520 KB Time limit exceeded
2 Halted 0 ms 0 KB -