Submission #1116102

# Submission time Handle Problem Language Result Execution time Memory
1116102 2024-11-21T09:06:48 Z SalihSahin Autobahn (COI21_autobahn) C++14
100 / 100
199 ms 38532 KB
#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;

const int inf = 1e16;
const int N = 1e3 + 5;

int32_t main(){
   ios_base::sync_with_stdio(false);
   cin.tie(0); cout.tie(0);
   int n, k, x;
   cin>>n>>k>>x;
   vector<array<int, 3> > upd;
   set<int> vis;

   for(int i = 0; i < n; i++){
      int l, t, r;
      cin>>l>>t>>r;

      if(r - l + 1 > t){
         upd.pb({l, i, 0});
         upd.pb({l+t, i, 1});
         upd.pb({r+1, i, 2});
         vis.insert(l);
         vis.insert(r+1);
         vis.insert(l+t);
      }
      else{
         upd.pb({l, i, 0});
         upd.pb({r+1, i, 2});
         vis.insert(l);
         vis.insert(r+1);
      }
   }

   sort(upd.begin(), upd.end());
   vector<int> col(n); // 0 yok, 1 iceride, 2 oduyor
   vector<array<int, 3> > odeme;
   int act = 0, ode = 0, ind = 0;

   for(auto i: vis){
      while(ind < upd.size() && upd[ind][0] <= i){
         if(upd[ind][2] == 0){
            act++;
            col[upd[ind][1]] = 1;
         }
         else if(upd[ind][2] == 1){
            col[upd[ind][1]] = 2;
            ode++;
         }
         else{
            if(col[upd[ind][1]] == 2) ode--;
            act--;
            col[upd[ind][1]] = 0;
         }
         ind++;
      }

      if(act >= k){
         odeme.pb({i, upd[ind][0]-1, ode});
      }
   }

   if(!odeme.size()){
      cout<<0<<endl;
      return 0;
   }


   int hh = 0, ans = 0;
   ind = 0;
   for(int i = 0; i < odeme.size(); i++){
      int l = odeme[i][0];
      while(ind < odeme.size() && odeme[ind][1] <= l + x - 1){
         hh += odeme[ind][2] * (odeme[ind][1] - odeme[ind][0] + 1);
         ind++;
      }
      int add = 0;
      if(ind < odeme.size() && l + x - 1 >= odeme[ind][0]){
         add = odeme[ind][2] * (l + x - 1 - odeme[ind][0] + 1);
      }

      ans = max(ans, hh + add);
      hh -= odeme[i][2] * (odeme[i][1] - odeme[i][0] + 1);
   }

   ind = odeme.size()-1;
   hh = 0;
   for(int i = odeme.size()-1; i >= 0; i--){
      int r = odeme[i][1];
      while(ind >= 0 && odeme[ind][0] >= r - x + 1){
         hh += odeme[ind][2] * (odeme[ind][1] - odeme[ind][0] + 1);
         ind--;
      }

      int add = 0;
      if(ind >= 0 && r - x + 1 <= odeme[ind][1]){
         add = odeme[ind][2] * (odeme[ind][1] - (r - x + 1) + 1);
      }

      ans = max(ans, hh + add);
      hh -= odeme[i][2] * (odeme[i][1] - odeme[i][0] + 1);
   }

   cout<<ans<<endl;
   return 0;
}

Compilation message

autobahn.cpp: In function 'int32_t main()':
autobahn.cpp:43:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |       while(ind < upd.size() && upd[ind][0] <= i){
      |             ~~~~^~~~~~~~~~~~
autobahn.cpp:73:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |    for(int i = 0; i < odeme.size(); i++){
      |                   ~~^~~~~~~~~~~~~~
autobahn.cpp:75:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |       while(ind < odeme.size() && odeme[ind][1] <= l + x - 1){
      |             ~~~~^~~~~~~~~~~~~~
autobahn.cpp:80:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |       if(ind < odeme.size() && l + x - 1 >= odeme[ind][0]){
      |          ~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 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 508 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 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 508 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 1 ms 592 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 2 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 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 508 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 1 ms 592 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 2 ms 764 KB Output is correct
21 Correct 193 ms 34276 KB Output is correct
22 Correct 184 ms 37092 KB Output is correct
23 Correct 199 ms 36268 KB Output is correct
24 Correct 169 ms 36836 KB Output is correct
25 Correct 172 ms 38532 KB Output is correct
26 Correct 164 ms 36580 KB Output is correct
27 Correct 177 ms 37600 KB Output is correct
28 Correct 184 ms 38064 KB Output is correct
29 Correct 184 ms 37768 KB Output is correct