답안 #947222

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
947222 2024-03-15T17:23:24 Z Nhoksocqt1 송신탑 (IOI22_towers) C++17
15 / 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, ksub1;
bool check_sub1;

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

    check_sub1 = 1;
    for (int i = 3; i <= nArr; ++i)
        check_sub1 &= (h[i - 2] < h[i - 1] || h[i - 1] > h[i]);
}

int max_towers(int l, int r, int d) {
    ++l, ++r;
    if(check_sub1) {
        int res = 1 + (l < ksub1 && ksub1 < r && max(h[l], h[r]) <= h[ksub1] - d);
        return res;
    }

    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
# 결과 실행 시간 메모리 Grader output
1 Correct 283 ms 944 KB Output is correct
2 Correct 528 ms 1620 KB Output is correct
3 Correct 557 ms 1612 KB Output is correct
4 Correct 571 ms 1612 KB Output is correct
5 Correct 539 ms 1620 KB Output is correct
6 Correct 571 ms 1624 KB Output is correct
7 Correct 614 ms 1612 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 344 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 476 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 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 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 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 472 KB Output is correct
22 Correct 7 ms 344 KB Output is correct
23 Correct 1 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 468 KB Output is correct
30 Correct 6 ms 344 KB Output is correct
31 Correct 6 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 6 ms 344 KB Output is correct
35 Correct 6 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 344 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 476 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 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 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 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 472 KB Output is correct
22 Correct 7 ms 344 KB Output is correct
23 Correct 1 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 468 KB Output is correct
30 Correct 6 ms 344 KB Output is correct
31 Correct 6 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 6 ms 344 KB Output is correct
35 Correct 6 ms 344 KB Output is correct
36 Correct 517 ms 1112 KB Output is correct
37 Correct 2069 ms 1616 KB Output is correct
38 Correct 333 ms 1612 KB Output is correct
39 Correct 1512 ms 1624 KB Output is correct
40 Correct 248 ms 1616 KB Output is correct
41 Execution timed out 4056 ms 1612 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4030 ms 1612 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4046 ms 804 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 344 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 476 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 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 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 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 472 KB Output is correct
22 Correct 7 ms 344 KB Output is correct
23 Correct 1 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 468 KB Output is correct
30 Correct 6 ms 344 KB Output is correct
31 Correct 6 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 6 ms 344 KB Output is correct
35 Correct 6 ms 344 KB Output is correct
36 Correct 517 ms 1112 KB Output is correct
37 Correct 2069 ms 1616 KB Output is correct
38 Correct 333 ms 1612 KB Output is correct
39 Correct 1512 ms 1624 KB Output is correct
40 Correct 248 ms 1616 KB Output is correct
41 Execution timed out 4056 ms 1612 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 283 ms 944 KB Output is correct
2 Correct 528 ms 1620 KB Output is correct
3 Correct 557 ms 1612 KB Output is correct
4 Correct 571 ms 1612 KB Output is correct
5 Correct 539 ms 1620 KB Output is correct
6 Correct 571 ms 1624 KB Output is correct
7 Correct 614 ms 1612 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 2 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 2 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 476 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 4 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 6 ms 344 KB Output is correct
31 Correct 6 ms 472 KB Output is correct
32 Correct 7 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 6 ms 344 KB Output is correct
35 Correct 2 ms 344 KB Output is correct
36 Correct 6 ms 472 KB Output is correct
37 Correct 6 ms 344 KB Output is correct
38 Correct 6 ms 344 KB Output is correct
39 Correct 6 ms 468 KB Output is correct
40 Correct 6 ms 344 KB Output is correct
41 Correct 6 ms 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 6 ms 344 KB Output is correct
45 Correct 6 ms 344 KB Output is correct
46 Correct 517 ms 1112 KB Output is correct
47 Correct 2069 ms 1616 KB Output is correct
48 Correct 333 ms 1612 KB Output is correct
49 Correct 1512 ms 1624 KB Output is correct
50 Correct 248 ms 1616 KB Output is correct
51 Execution timed out 4056 ms 1612 KB Time limit exceeded
52 Halted 0 ms 0 KB -