답안 #669794

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
669794 2022-12-07T09:56:16 Z Cyanmond Autobahn (COI21_autobahn) C++17
100 / 100
247 ms 14996 KB
#include <bits/stdc++.h>

using i64 = long long;

int main() {
    int N, K;
    i64 X;
    std::cin >> N >> K >> X;

    std::vector<i64> L(N), T(N), R(N);
    std::vector<i64> press;
    for (int i = 0; i < N; ++i) {
        std::cin >> L[i] >> T[i] >> R[i];
        ++R[i];
        T[i] += L[i];
        T[i] = std::min(T[i], R[i]);
        press.push_back(L[i]);
        press.push_back(T[i]);
        press.push_back(R[i]);
    }
    std::sort(press.begin(), press.end());
    press.erase(std::unique(press.begin(), press.end()), press.end());

    auto calc_index = [&](const i64 x) {
        return (int)(std::lower_bound(press.begin(), press.end(), x) - press.begin());
    };

    const int M = (int)press.size();
    std::vector<i64> people(M);
    for (int i = 0; i < N; ++i) {
        ++people[calc_index(L[i])];
        --people[calc_index(R[i])];
    }
    for (int i = 1; i < M; ++i) {
        people[i] += people[i - 1];
    }

    std::vector<i64> score(M);
    for (int i = 0; i < N; ++i) {
        ++score[calc_index(T[i])];
        --score[calc_index(R[i])];
    }
    for (int i = 1; i < M; ++i) {
        score[i] += score[i - 1];
    }
    for (int i = 0; i < M; ++i) {
        if (people[i] < K) {
            score[i] = 0;
        }
    }

    std::vector<i64> score_r(M + 1);
    for (int i = 0; i < M; ++i) {
        score_r[i + 1] += score_r[i] + score[i] * (i + 1 == M ? 0 : press[i + 1] - press[i]);
    }

    auto calc_score = [&](const i64 l, const i64 r) {
        const int l_index = calc_index(l);
        const int r_index = calc_index(r);
        assert(press[l_index] == l or press[r_index] == r);
        if (press[l_index] == l) {
            i64 ret = score_r[r_index] - score_r[l_index];
            if (r_index != M) {
                ret -= score[r_index - 1] * (press[r_index] - r);
            }
            return ret;
        } else {
            i64 ret = score_r[r_index] - score_r[l_index];
            if (l_index != 0) {
                ret += score[l_index - 1] * (press[l_index] - l);
            }
            return ret;
        }
    };

    i64 answer = 0;
    for (int i = 0; i < M; ++i) {
        answer = std::max(answer, calc_score(press[i], press[i] + X));
        answer = std::max(answer, calc_score(press[i] - X, press[i]));
    }

    std::cout << answer << std::endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 308 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 352 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 308 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 352 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 247 ms 14800 KB Output is correct
22 Correct 241 ms 14804 KB Output is correct
23 Correct 244 ms 14888 KB Output is correct
24 Correct 233 ms 14996 KB Output is correct
25 Correct 229 ms 14892 KB Output is correct
26 Correct 230 ms 14852 KB Output is correct
27 Correct 226 ms 14848 KB Output is correct
28 Correct 221 ms 14896 KB Output is correct
29 Correct 223 ms 14856 KB Output is correct