답안 #420609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
420609 2021-06-08T12:56:52 Z HappyPacMan Autobahn (COI21_autobahn) C++14
100 / 100
262 ms 12204 KB
#include <bits/stdc++.h>
using namespace std;
const int MXN = 1e5 + 5;
int N,K,X,l[MXN],t[MXN],r[MXN],prfcnt[10*MXN],prflate[10*MXN];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> N >> K >> X;
    vector<int> coor;
    for(int i=0;i<N;i++){
        cin >> l[i] >> t[i] >> r[i];
        coor.push_back(l[i]-1); coor.push_back(l[i]); coor.push_back(l[i]+1);
        coor.push_back(l[i]+t[i]-1); coor.push_back(l[i]+t[i]); coor.push_back(l[i]+t[i]+1);
        coor.push_back(r[i]-1); coor.push_back(r[i]); coor.push_back(r[i]+1);
    }
    sort(coor.begin(),coor.end());
    coor.erase(unique(coor.begin(),coor.end()),coor.end());
    auto fnidx = [&](int u){
        return lower_bound(coor.begin(),coor.end(),u)-coor.begin();
    };
    for(int i=0;i<N;i++){
        prfcnt[fnidx(l[i])]++, prfcnt[fnidx(r[i]+1)]--;
        if(l[i]+t[i] <= r[i]) prflate[fnidx(l[i]+t[i])]++, prflate[fnidx(r[i]+1)]--;
    }
    for(int i=1;i<coor.size();i++){
        prfcnt[i] += prfcnt[i-1];
        prflate[i] += prflate[i-1];
    }
    // for(int i=0;i<coor.size();i++) cout << prfcnt[i] << ' '; cout << '\n';
    // for(int i=0;i<coor.size();i++) cout << prflate[i] << ' '; cout << '\n';
    int64_t mx = 0,cost = 0;
    for(int i=1,j=1;i<coor.size();i++){
        if(prfcnt[i] >= K) cost += (coor[i]-coor[i-1]) * 1LL * prflate[i];
        while(coor[i]-coor[j] > X){
            j++;
            if(prfcnt[j] >= K) cost -= (coor[j]-coor[j-1]) * 1LL * prflate[j];
        }
        int64_t temp = cost;
        if(prfcnt[j] >= K) temp += min(coor[j]-coor[j-1],X-(coor[i]-coor[j])) * 1LL * prflate[j];
        mx = max(mx,temp);
    }
    cost = 0;
    for(int i=1,j=1;i<coor.size()-1;i++){
        if(prfcnt[i] >= K) cost -= (coor[i]-coor[i-1]) * 1LL * prflate[i];
        while(j+1 < coor.size() && coor[j+1]-coor[i] <= X){
            j++;
            if(prfcnt[j] >= K) cost += (coor[j]-coor[j-1]) * 1LL * prflate[j];
        }
        int64_t temp = cost;
        if(prfcnt[j+1] >= K) temp += min(coor[j+1]-coor[j],X-(coor[j]-coor[i])) * 1LL * prflate[j+1];
        mx = max(mx,temp);
    }
    cout << mx << '\n';
}

Compilation message

autobahn.cpp: In function 'int main()':
autobahn.cpp:27:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i=1;i<coor.size();i++){
      |                 ~^~~~~~~~~~~~
autobahn.cpp:34:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i=1,j=1;i<coor.size();i++){
      |                     ~^~~~~~~~~~~~
autobahn.cpp:45:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int i=1,j=1;i<coor.size()-1;i++){
      |                     ~^~~~~~~~~~~~~~
autobahn.cpp:47:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         while(j+1 < coor.size() && coor[j+1]-coor[i] <= X){
      |               ~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 4 ms 456 KB Output is correct
20 Correct 3 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 4 ms 456 KB Output is correct
20 Correct 3 ms 460 KB Output is correct
21 Correct 241 ms 12156 KB Output is correct
22 Correct 229 ms 12204 KB Output is correct
23 Correct 213 ms 12080 KB Output is correct
24 Correct 206 ms 12148 KB Output is correct
25 Correct 236 ms 12076 KB Output is correct
26 Correct 231 ms 12184 KB Output is correct
27 Correct 262 ms 12104 KB Output is correct
28 Correct 224 ms 12180 KB Output is correct
29 Correct 255 ms 12184 KB Output is correct