답안 #920718

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
920718 2024-02-03T00:49:29 Z hasuhasuiro Autobahn (COI21_autobahn) C++17
100 / 100
971 ms 99628 KB
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, K, X;
    cin >> N >> K >> X;
    vector l(N, 0), r(N, 0), t(N, 0);
    for(int i = 0; i < N; i++) { cin >> l[i] >> t[i] >> r[i]; r[i]++; }
    /* 座標圧縮用の座標 */
    vector P(0, 0);
    for(int i = 0; i < N; i++) { P.push_back(l[i]), P.push_back(r[i]); } /* 各区間の始点終点 */
    for(int i = 0; i < N; i++) { if(l[i]+t[i] < r[i]) { P.push_back(l[i]+t[i]); } } /* 追加料金のかかる区間の始点 */
    sort(begin(P), end(P));
    P.erase(unique(begin(P), end(P)), end(P));
    map<int, int> mp2;
    for(int i = 0; i < (int)size(P); i++) { mp2[P[i]] = 1; }
    int sizep(size(P));
    for(int i = 0; i < sizep; i++) {
        P.push_back(P[i]+X), P.push_back(P[i]-X);
        if(mp2.find(P[i]+X) == end(mp2)) { mp2[P[i]+X] = 2; }
        if(mp2.find(P[i]-X) == end(mp2)) { mp2[P[i]-X] = 3; }
    } /* ある点から X の距離の点 */
    sort(begin(P), end(P));
    P.erase(unique(begin(P), end(P)), end(P));
 
    /* P の逆引きできるような連想配列 */
    map<int, int> mp;
    for(int i = 0; i < (int)size(P); i++) { mp[P[i]] = i; }
    vector imos(size(P), 0);
    for(int i = 0; i < N; i++) { imos[mp[l[i]]]++; imos[mp[r[i]]]--; } /* 各区間の区間加算 */
    for(int i = 0; i+1 < (int)size(P); i++) { imos[i+1] += imos[i]; } /* 求解 */
 
    vector imos2(size(P), 0);
    for(int i = 0; i < N; i++) { if(l[i]+t[i] < r[i]) { imos2[mp[l[i]+t[i]]]++; imos2[mp[r[i]]]--; } } /* 追加料金の区間加算 */
    for(int i = 0; i+1 < (int)size(P); i++) { imos2[i+1] += imos2[i]; } /* 求解 */
    for(int i = 0; i < (int)size(P); i++) { if(imos[i] < K) { imos2[i] = 0; } } /* 許される場合は除外する */
 
    /* 尺取り法 */
    long long ans(0), res(0);
    for(int i = 0, j = 0; i+1 < (int)size(P); i++) {
        if(mp2[P[i]] == 2) {
            res -= (long long)(imos2[mp[P[i]]]) * (long long)(P[i+1] - P[i]); /* 左端を加算 */    
            continue;
        }
        for(; j < (int)size(P); j++) {
            if(P[i]+X <= P[j]) { break; }
            else if(j+1 < (int)size(P)) { res += (long long)(imos2[mp[P[j]]]) * (long long)((P[j+1]-P[j])); } /* 右端を加算 */
            else break;
        }
        ans = max(res, ans);
        res -= (long long)(imos2[mp[P[i]]]) * (long long)(P[i+1] - P[i]); /* 左端を加算 */    
    }
    cout << ans << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 915 ms 96704 KB Output is correct
22 Correct 971 ms 99416 KB Output is correct
23 Correct 952 ms 99336 KB Output is correct
24 Correct 887 ms 99628 KB Output is correct
25 Correct 924 ms 99292 KB Output is correct
26 Correct 890 ms 99264 KB Output is correct
27 Correct 874 ms 99264 KB Output is correct
28 Correct 881 ms 99428 KB Output is correct
29 Correct 902 ms 99328 KB Output is correct