Submission #1003013

# Submission time Handle Problem Language Result Execution time Memory
1003013 2024-06-20T00:54:18 Z hyakup Autobahn (COI21_autobahn) C++17
50 / 100
110 ms 16216 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

struct evento{
  int x, type, id; evento( int x = 0, int type = 0, int id = 0 ) : x(x), type(type), id(id) {}
  bool operator < ( evento e ){
    if( x == e.x ) type < e.type;
    return x < e.x;
  }
}; vector<evento> line(1);

const int maxn = 1e5 + 10;
vector<int> resp( 2*maxn, -1 );

int main(){
  int n, k, x; cin >> n >> k >> x;
  for( int i = 1; i <= n; i++ ){
    int l, t, r; cin >> l >> t >> r;
    line.push_back( evento( l - 1, 1, 0 ) );
    line.push_back( evento( l + t - 1, 2, 0 ) );

    line.push_back( evento( r - x, 3, 2*i ) );
    line.push_back( evento( r, 3, 2*i ) );

    line.push_back( evento( l + t - 1, 3, 2*i + 1 ) );
    line.push_back( evento( l + t + x - 1, 3, 2*i + 1 ) );

    line.push_back( evento( r, 4, 0 ) );
  }
  sort( line.begin(), line.end() );

  ll ativos = 0, criticos = 0;
  ll sum = 0;
  ll ans = 0;
  for(int i = 1; i < line.size(); i++ ){
    if( ativos >= k ) sum += 1LL*criticos*(line[i].x - line[i - 1].x );
    auto cur = line[i];
    if( cur.type == 1 ) ativos++;
    if( cur.type == 2 ) criticos++;
    if( cur.type == 3 ){
      if( resp[cur.id] == -1 ) resp[cur.id] = sum;
      else ans = max( ans, sum - resp[cur.id] );
    }
    if( cur.type == 4 ){
        ativos--;
        criticos--;
    }
  }
  cout << ans << endl;
}

Compilation message

autobahn.cpp: In member function 'bool evento::operator<(evento)':
autobahn.cpp:9:25: warning: statement has no effect [-Wunused-value]
    9 |     if( x == e.x ) type < e.type;
      |                    ~~~~~^~~~~~~~
autobahn.cpp: In function 'int main()':
autobahn.cpp:37:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<evento>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   for(int i = 1; i < line.size(); i++ ){
      |                  ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 0 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 0 ms 1116 KB Output is correct
6 Correct 0 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 0 ms 1124 KB Output is correct
9 Correct 0 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 0 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 0 ms 1116 KB Output is correct
6 Correct 0 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 0 ms 1124 KB Output is correct
9 Correct 0 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1372 KB Output is correct
13 Correct 1 ms 1372 KB Output is correct
14 Correct 1 ms 1624 KB Output is correct
15 Correct 1 ms 1368 KB Output is correct
16 Correct 1 ms 1372 KB Output is correct
17 Correct 1 ms 1372 KB Output is correct
18 Correct 1 ms 1372 KB Output is correct
19 Correct 1 ms 1240 KB Output is correct
20 Correct 1 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 0 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 0 ms 1116 KB Output is correct
6 Correct 0 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 0 ms 1124 KB Output is correct
9 Correct 0 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1372 KB Output is correct
13 Correct 1 ms 1372 KB Output is correct
14 Correct 1 ms 1624 KB Output is correct
15 Correct 1 ms 1368 KB Output is correct
16 Correct 1 ms 1372 KB Output is correct
17 Correct 1 ms 1372 KB Output is correct
18 Correct 1 ms 1372 KB Output is correct
19 Correct 1 ms 1240 KB Output is correct
20 Correct 1 ms 1372 KB Output is correct
21 Incorrect 110 ms 16216 KB Output isn't correct
22 Halted 0 ms 0 KB -