Submission #947221

# Submission time Handle Problem Language Result Execution time Memory
947221 2024-03-15T17:18:20 Z Nhoksocqt1 Radio Towers (IOI22_towers) C++17
11 / 100
4000 ms 1624 KB
#ifndef Nhoksocqt1
    #include "towers.h"
#endif // Nhoksocqt1
#include<bits/stdc++.h>
using namespace std;

#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;

template<class X, class Y>
	inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
	inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

const int MAXN = 100005;

int dp[MAXN];
int h[MAXN], nArr;

void init(int _N, vector<int> _H) {
    nArr = _N;
    for (int i = 1; i <= nArr; ++i)
        h[i] = _H[i - 1];
}

int max_towers(int l, int r, int d) {
    ++l, ++r;
    for (int i = l; i <= r; ++i)
        dp[i] = 1;

    for (int i = l; i <= r; ++i) {
        int k(i + 1);
        for (int j = i + 2; j <= r; ++j) {
            if(h[k] - d >= max(h[i], h[j]))
                dp[j] = max(dp[j], dp[i] + 1);

            if(h[j] > h[k])
                k = j;
        }
    }

    int res(0);
    for (int i = l; i <= r; ++i)
        res = max(res, dp[i]);

    return res;
}

#ifdef Nhoksocqt1

int main(void) {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    #define TASK "towers"
    if(fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }

    vector<int> _H;
    int _N, _Q;
    cin >> _N;

    _H.resize(_N);
    for (int i = 0; i < _N; ++i)
        cin >> _H[i];

    init(_N, _H);

    cin >> _Q;
    for (int t = 0; t < _Q; ++t) {
        int _L, _R, _D;
        cin >> _L >> _R >> _D;
        cout << "ANSWER FOR " << _L + 1 << ' ' << _R + 1 << ' ' << _D << ": " << max_towers(_L, _R, _D) << '\n';
    }

    return 0;
}

#endif // Nhoksocqt1
# Verdict Execution time Memory Grader output
1 Execution timed out 4043 ms 1244 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 4 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 6 ms 344 KB Output is correct
21 Correct 6 ms 344 KB Output is correct
22 Correct 6 ms 344 KB Output is correct
23 Correct 7 ms 344 KB Output is correct
24 Correct 6 ms 344 KB Output is correct
25 Correct 2 ms 344 KB Output is correct
26 Correct 6 ms 472 KB Output is correct
27 Correct 6 ms 344 KB Output is correct
28 Correct 6 ms 344 KB Output is correct
29 Correct 6 ms 452 KB Output is correct
30 Correct 6 ms 472 KB Output is correct
31 Correct 6 ms 344 KB Output is correct
32 Correct 6 ms 344 KB Output is correct
33 Correct 6 ms 472 KB Output is correct
34 Correct 6 ms 480 KB Output is correct
35 Correct 6 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 4 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 6 ms 344 KB Output is correct
21 Correct 6 ms 344 KB Output is correct
22 Correct 6 ms 344 KB Output is correct
23 Correct 7 ms 344 KB Output is correct
24 Correct 6 ms 344 KB Output is correct
25 Correct 2 ms 344 KB Output is correct
26 Correct 6 ms 472 KB Output is correct
27 Correct 6 ms 344 KB Output is correct
28 Correct 6 ms 344 KB Output is correct
29 Correct 6 ms 452 KB Output is correct
30 Correct 6 ms 472 KB Output is correct
31 Correct 6 ms 344 KB Output is correct
32 Correct 6 ms 344 KB Output is correct
33 Correct 6 ms 472 KB Output is correct
34 Correct 6 ms 480 KB Output is correct
35 Correct 6 ms 348 KB Output is correct
36 Correct 527 ms 1112 KB Output is correct
37 Correct 2075 ms 1620 KB Output is correct
38 Correct 335 ms 1616 KB Output is correct
39 Correct 1515 ms 1612 KB Output is correct
40 Correct 249 ms 1608 KB Output is correct
41 Execution timed out 4066 ms 1624 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4035 ms 1612 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4016 ms 808 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 4 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 6 ms 344 KB Output is correct
21 Correct 6 ms 344 KB Output is correct
22 Correct 6 ms 344 KB Output is correct
23 Correct 7 ms 344 KB Output is correct
24 Correct 6 ms 344 KB Output is correct
25 Correct 2 ms 344 KB Output is correct
26 Correct 6 ms 472 KB Output is correct
27 Correct 6 ms 344 KB Output is correct
28 Correct 6 ms 344 KB Output is correct
29 Correct 6 ms 452 KB Output is correct
30 Correct 6 ms 472 KB Output is correct
31 Correct 6 ms 344 KB Output is correct
32 Correct 6 ms 344 KB Output is correct
33 Correct 6 ms 472 KB Output is correct
34 Correct 6 ms 480 KB Output is correct
35 Correct 6 ms 348 KB Output is correct
36 Correct 527 ms 1112 KB Output is correct
37 Correct 2075 ms 1620 KB Output is correct
38 Correct 335 ms 1616 KB Output is correct
39 Correct 1515 ms 1612 KB Output is correct
40 Correct 249 ms 1608 KB Output is correct
41 Execution timed out 4066 ms 1624 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4043 ms 1244 KB Time limit exceeded
2 Halted 0 ms 0 KB -