답안 #628552

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
628552 2022-08-13T13:21:40 Z dqhungdl 송신탑 (IOI22_towers) C++17
15 / 100
4000 ms 9296 KB
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;

const int MAX = 1e5 + 5;
int N, maxH[MAX][20];
bool isMountain = true;
vector<int> H;

int get(int l, int r) {
    int k = log2(r - l + 1);
    return max(maxH[l][k], maxH[r - (1 << k) + 1][k]);
}

void init(int _N, vector<int> _H) {
    N = _N, H = _H;
    for (int i = 0; i < N; i++)
        maxH[i][0] = H[i];
    for (int t = 1; t <= 18; t++)
        for (int i = 0; i + (1 << t) - 1 < N; i++)
            maxH[i][t] = max(maxH[i][t - 1], maxH[i + (1 << (t - 1))][t - 1]);
    int id = max_element(H.begin(), H.end()) - H.begin();
    for (int i = id; i > 0 && isMountain; i--)
        isMountain &= (H[i] > H[i - 1]);
    for (int i = id; i < N - 1 && isMountain; i++)
        isMountain &= (H[i] > H[i + 1]);
}

int max_towers(int L, int R, int D) {
    if (isMountain)
        return get(L, R) - D >= max(H[L], H[R]) ? 2 : 1;
    vector<int> f(R - L + 1, 1);
    int rs = 0;
    for (int i = L; i <= R; i++) {
        for (int j = L; j < i - 1; j++) {
            if (get(j + 1, i - 1) - D >= max(H[i], H[j]))
                f[i - L] = max(f[i - L], f[j - L] + 1);
        }
        rs = max(rs, f[i - L]);
    }
    return rs;
}

//int main() {
//    freopen("../_input", "r", stdin);
//    int N, Q;
//    assert(2 == scanf("%d %d", &N, &Q));
//    std::vector<int> H(N);
//    for (int i = 0; i < N; ++i) {
//        assert(1 == scanf("%d", &H[i]));
//    }
//    init(N, H);
//
//    for (int i = 0; i < Q; ++i) {
//        int L, R, D;
//        assert(3 == scanf("%d %d %d", &L, &R, &D));
//        printf("%d\n", max_towers(L, R, D));
//    }
//    return 0;
//}
# 결과 실행 시간 메모리 Grader output
1 Correct 395 ms 5584 KB Output is correct
2 Correct 831 ms 9296 KB Output is correct
3 Correct 779 ms 9204 KB Output is correct
4 Correct 597 ms 9252 KB Output is correct
5 Correct 768 ms 9296 KB Output is correct
6 Correct 841 ms 9296 KB Output is correct
7 Correct 878 ms 9296 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 12 ms 480 KB Output is correct
3 Correct 9 ms 476 KB Output is correct
4 Correct 6 ms 464 KB Output is correct
5 Correct 8 ms 464 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 7 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 2 ms 464 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 0 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 17 ms 476 KB Output is correct
17 Correct 3 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 3 ms 464 KB Output is correct
20 Correct 35 ms 464 KB Output is correct
21 Correct 31 ms 464 KB Output is correct
22 Correct 32 ms 476 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 33 ms 464 KB Output is correct
25 Correct 6 ms 336 KB Output is correct
26 Correct 33 ms 464 KB Output is correct
27 Correct 44 ms 464 KB Output is correct
28 Correct 32 ms 464 KB Output is correct
29 Correct 31 ms 464 KB Output is correct
30 Correct 33 ms 464 KB Output is correct
31 Correct 33 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 31 ms 464 KB Output is correct
35 Correct 30 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 12 ms 480 KB Output is correct
3 Correct 9 ms 476 KB Output is correct
4 Correct 6 ms 464 KB Output is correct
5 Correct 8 ms 464 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 7 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 2 ms 464 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 0 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 17 ms 476 KB Output is correct
17 Correct 3 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 3 ms 464 KB Output is correct
20 Correct 35 ms 464 KB Output is correct
21 Correct 31 ms 464 KB Output is correct
22 Correct 32 ms 476 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 33 ms 464 KB Output is correct
25 Correct 6 ms 336 KB Output is correct
26 Correct 33 ms 464 KB Output is correct
27 Correct 44 ms 464 KB Output is correct
28 Correct 32 ms 464 KB Output is correct
29 Correct 31 ms 464 KB Output is correct
30 Correct 33 ms 464 KB Output is correct
31 Correct 33 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 31 ms 464 KB Output is correct
35 Correct 30 ms 476 KB Output is correct
36 Correct 2931 ms 6068 KB Output is correct
37 Execution timed out 4037 ms 9292 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4046 ms 9132 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4059 ms 2384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 12 ms 480 KB Output is correct
3 Correct 9 ms 476 KB Output is correct
4 Correct 6 ms 464 KB Output is correct
5 Correct 8 ms 464 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 7 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 2 ms 464 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 0 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 17 ms 476 KB Output is correct
17 Correct 3 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 3 ms 464 KB Output is correct
20 Correct 35 ms 464 KB Output is correct
21 Correct 31 ms 464 KB Output is correct
22 Correct 32 ms 476 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 33 ms 464 KB Output is correct
25 Correct 6 ms 336 KB Output is correct
26 Correct 33 ms 464 KB Output is correct
27 Correct 44 ms 464 KB Output is correct
28 Correct 32 ms 464 KB Output is correct
29 Correct 31 ms 464 KB Output is correct
30 Correct 33 ms 464 KB Output is correct
31 Correct 33 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 31 ms 464 KB Output is correct
35 Correct 30 ms 476 KB Output is correct
36 Correct 2931 ms 6068 KB Output is correct
37 Execution timed out 4037 ms 9292 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 395 ms 5584 KB Output is correct
2 Correct 831 ms 9296 KB Output is correct
3 Correct 779 ms 9204 KB Output is correct
4 Correct 597 ms 9252 KB Output is correct
5 Correct 768 ms 9296 KB Output is correct
6 Correct 841 ms 9296 KB Output is correct
7 Correct 878 ms 9296 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 0 ms 336 KB Output is correct
12 Correct 12 ms 480 KB Output is correct
13 Correct 9 ms 476 KB Output is correct
14 Correct 6 ms 464 KB Output is correct
15 Correct 8 ms 464 KB Output is correct
16 Correct 2 ms 464 KB Output is correct
17 Correct 7 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 464 KB Output is correct
21 Correct 2 ms 464 KB Output is correct
22 Correct 0 ms 208 KB Output is correct
23 Correct 0 ms 464 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 464 KB Output is correct
26 Correct 17 ms 476 KB Output is correct
27 Correct 3 ms 464 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 3 ms 464 KB Output is correct
30 Correct 35 ms 464 KB Output is correct
31 Correct 31 ms 464 KB Output is correct
32 Correct 32 ms 476 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 33 ms 464 KB Output is correct
35 Correct 6 ms 336 KB Output is correct
36 Correct 33 ms 464 KB Output is correct
37 Correct 44 ms 464 KB Output is correct
38 Correct 32 ms 464 KB Output is correct
39 Correct 31 ms 464 KB Output is correct
40 Correct 33 ms 464 KB Output is correct
41 Correct 33 ms 464 KB Output is correct
42 Correct 1 ms 464 KB Output is correct
43 Correct 1 ms 464 KB Output is correct
44 Correct 31 ms 464 KB Output is correct
45 Correct 30 ms 476 KB Output is correct
46 Correct 2931 ms 6068 KB Output is correct
47 Execution timed out 4037 ms 9292 KB Time limit exceeded
48 Halted 0 ms 0 KB -