답안 #836531

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
836531 2023-08-24T12:23:50 Z tengiz05 송신탑 (IOI22_towers) C++17
23 / 100
4000 ms 9280 KB
#include "towers.h"

#include <bits/stdc++.h>
using namespace std;

vector<int> h;
int n;
void init(int N, vector<int> H) {
    n = N;
    h = H;
}

struct SegmentTree {
    int n;
    vector<int> f;
    SegmentTree(int n) : n(n), f(4 * n) {}
    void modify(int p, int l, int r, int x, int y) {
        if (l == r - 1) {
            f[p] = y;
        } else {
            int m = (l + r) / 2;
            if (x < m) {
                modify(2 * p, l, m, x, y);
            } else {
                modify(2 * p + 1, m, r, x, y);
            }
            f[p] = max(f[2 * p], f[2 * p + 1]);
        }
    }
    void modify(int x, int y) {
        modify(1, 0, n, x, y);
    }
    int rangeMax(int p, int l, int r, int x, int y) {
        if (r <= x || y <= l) return 0;
        if (x <= l && r <= y) return f[p];
        int m = (l + r) / 2;
        return max(rangeMax(2 * p, l, m, x, y), rangeMax(2 * p + 1, m, r, x, y));
    }
    int rangeMax(int l, int r) {
        return rangeMax(1, 0, n, l, r);
    }
};

int max_towers(int l, int r, int D) {
    deque<pair<int, int>> st;
    vector<int> nxt(n, -1);
    for (int i = n - 1; i >= 0; i--) {
        while (!st.empty() && h[st.front().second] <= h[i]) st.pop_front();
        st.push_front({h[i], i});
        auto p = lower_bound(st.begin(), st.end(), pair{h[i] + D, -1});
        if (p != st.end()) {
            nxt[i] = p->second;
        }
    }
    st.clear();
    vector<int> prev(n, -1);
    for (int i = 0; i < n; i++) {
        while (!st.empty() && h[st.front().second] <= h[i]) st.pop_front();
        st.push_front({h[i], i});
        auto p = lower_bound(st.begin(), st.end(), pair{h[i] + D, -1});
        if (p != st.end()) {
            prev[i] = p->second;
        }
    }
    vector<vector<int>> events(n);
    vector<int> dp(n);
    for (int i = l; i <= r; i++) {
        if (nxt[i] != -1) {
            events[nxt[i]].push_back(i);
        }
    }
    SegmentTree s(n);
    for (int i = l; i <= r; i++) {
        // dp[i] = 1;
        // for (int j = l; j < i; j++) {
            // if (nxt[j] != -1 && prev[i] != -1 && nxt[j] < i && prev[i] > j) {
                // dp[i] = max(dp[i], dp[j] + 1);
            // }
        // }
        dp[i] = s.rangeMax(l, prev[i]) + 1;
        for (auto j : events[i]) {
            s.modify(j, dp[j]);
        }
    }
    return *max_element(dp.begin(), dp.end());
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4006 ms 4696 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 480 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 0 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 480 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 0 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 15 ms 4304 KB Output is correct
37 Correct 20 ms 6304 KB Output is correct
38 Correct 19 ms 6292 KB Output is correct
39 Correct 16 ms 6164 KB Output is correct
40 Correct 18 ms 6344 KB Output is correct
41 Correct 26 ms 6808 KB Output is correct
42 Correct 15 ms 6184 KB Output is correct
43 Correct 22 ms 6700 KB Output is correct
44 Correct 20 ms 6976 KB Output is correct
45 Correct 18 ms 6344 KB Output is correct
46 Correct 19 ms 6592 KB Output is correct
47 Correct 23 ms 6720 KB Output is correct
48 Correct 23 ms 6472 KB Output is correct
49 Correct 22 ms 6180 KB Output is correct
50 Correct 20 ms 6976 KB Output is correct
51 Correct 20 ms 7336 KB Output is correct
52 Correct 40 ms 7744 KB Output is correct
53 Correct 33 ms 7720 KB Output is correct
54 Correct 34 ms 7740 KB Output is correct
55 Correct 31 ms 6964 KB Output is correct
56 Correct 35 ms 9280 KB Output is correct
57 Correct 24 ms 6484 KB Output is correct
58 Correct 28 ms 6852 KB Output is correct
59 Correct 36 ms 7236 KB Output is correct
60 Correct 34 ms 7704 KB Output is correct
61 Correct 30 ms 7568 KB Output is correct
62 Correct 26 ms 7256 KB Output is correct
63 Correct 30 ms 7612 KB Output is correct
64 Correct 23 ms 6924 KB Output is correct
65 Correct 22 ms 6888 KB Output is correct
66 Correct 28 ms 7036 KB Output is correct
67 Correct 22 ms 6940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4097 ms 7692 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4009 ms 2064 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 480 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 0 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 15 ms 4304 KB Output is correct
37 Correct 20 ms 6304 KB Output is correct
38 Correct 19 ms 6292 KB Output is correct
39 Correct 16 ms 6164 KB Output is correct
40 Correct 18 ms 6344 KB Output is correct
41 Correct 26 ms 6808 KB Output is correct
42 Correct 15 ms 6184 KB Output is correct
43 Correct 22 ms 6700 KB Output is correct
44 Correct 20 ms 6976 KB Output is correct
45 Correct 18 ms 6344 KB Output is correct
46 Correct 19 ms 6592 KB Output is correct
47 Correct 23 ms 6720 KB Output is correct
48 Correct 23 ms 6472 KB Output is correct
49 Correct 22 ms 6180 KB Output is correct
50 Correct 20 ms 6976 KB Output is correct
51 Correct 20 ms 7336 KB Output is correct
52 Correct 40 ms 7744 KB Output is correct
53 Correct 33 ms 7720 KB Output is correct
54 Correct 34 ms 7740 KB Output is correct
55 Correct 31 ms 6964 KB Output is correct
56 Correct 35 ms 9280 KB Output is correct
57 Correct 24 ms 6484 KB Output is correct
58 Correct 28 ms 6852 KB Output is correct
59 Correct 36 ms 7236 KB Output is correct
60 Correct 34 ms 7704 KB Output is correct
61 Correct 30 ms 7568 KB Output is correct
62 Correct 26 ms 7256 KB Output is correct
63 Correct 30 ms 7612 KB Output is correct
64 Correct 23 ms 6924 KB Output is correct
65 Correct 22 ms 6888 KB Output is correct
66 Correct 28 ms 7036 KB Output is correct
67 Correct 22 ms 6940 KB Output is correct
68 Execution timed out 4097 ms 7692 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4006 ms 4696 KB Time limit exceeded
2 Halted 0 ms 0 KB -