답안 #920371

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
920371 2024-02-02T13:48:45 Z zeta7532 Autobahn (COI21_autobahn) C++17
100 / 100
168 ms 16492 KB
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
const ll mod = 998244353;
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define faster ios::sync_with_stdio(false);cin.tie(nullptr)

ll f(ll x,ll a,ll va,ll b,ll vb){
    ll ans=0;
    if(va<vb){
        swap(a,b);
        swap(va,vb);
    }
    ans+=va*min(x,a);
    x-=min(x,a);
    ans+=vb*min(x,b);
    x-=min(x,b);
    return ans;
}

int main() {
    ll N,K,X;
    cin >> N >> K >> X;
    vector<ll> l(N),t(N),r(N);
    vector<ll> x;
    rep(i,N){
        cin >> l[i] >> t[i] >> r[i];
        x.push_back(l[i]);
        x.push_back(r[i]+1);
        if(l[i]+t[i]<=r[i]){
            x.push_back(l[i]+t[i]);
        }
    }
    x.push_back(0);
    x.push_back(1LL<<30);
    sort(all(x));
    x.erase(unique(all(x)),x.end());
    ll M=x.size()-1;
    vector<ll> A(M,0);
    vector<ll> B(M,0);
    rep(i,N){
        ll a=lower_bound(all(x),l[i])-x.begin();
        ll b=lower_bound(all(x),l[i]+t[i])-x.begin();
        ll c=lower_bound(all(x),r[i]+1)-x.begin();
        A[a]++;
        A[c]--;
        if(l[i]+t[i]<=r[i]){
            B[b]++;
            B[c]--;
        }
    }
    rep(i,M-1) A[i+1]+=A[i],B[i+1]+=B[i];
    vector<ll> cum(M,0);
    if(A[0]>=K) cum[0]+=B[0]*(x[1]-x[0]);
    for(ll i=1;i<M;i++){
        cum[i]=cum[i-1];
        if(A[i]>=K) cum[i]+=B[i]*(x[i+1]-x[i]);
    }
    ll ans=0;
    for(ll i=1;i<M;i++){
        ll ok=i,ng=M;
        while(ng-ok>1){
            ll mid=(ok+ng)/2;
            if(x[mid]>x[i]+X) ng=mid;
            else ok=mid;
        }
        ll len=X-(x[ok]-x[i]);
        ll l=x[i]-x[i-1];
        ll val_l=0;
        if(A[i-1]>=K) val_l=B[i-1];
        ll r=x[ok+1]-x[ok];
        ll val_r=0;
        if(A[ok]>=K) val_r=B[ok];
        ll cnt=cum[ok-1]-cum[i-1]+f(len,l,val_l,r,val_r);
        ans=max(ans,cnt);
        if(i==ok) continue;
        i++;
        len=X-(x[ok]-x[i]);
        l=x[i]-x[i-1];
        val_l=0;
        if(A[i-1]>=K) val_l=B[i-1];
        r=x[ok+1]-x[ok];
        val_r=0;
        if(A[ok]>=K) val_r=B[ok];
        cnt=cum[ok-1]-cum[i-1]+f(len,l,val_l,r,val_r);
        ans=max(ans,cnt);
        i--;
    }
    cout << ans << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 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 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 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 2 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 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 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 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 2 ms 600 KB Output is correct
21 Correct 168 ms 16040 KB Output is correct
22 Correct 167 ms 16316 KB Output is correct
23 Correct 166 ms 16492 KB Output is correct
24 Correct 166 ms 15292 KB Output is correct
25 Correct 165 ms 15132 KB Output is correct
26 Correct 161 ms 14780 KB Output is correct
27 Correct 162 ms 16064 KB Output is correct
28 Correct 163 ms 16316 KB Output is correct
29 Correct 166 ms 15708 KB Output is correct