Submission #320259

# Submission time Handle Problem Language Result Execution time Memory
320259 2020-11-08T06:41:56 Z AlexLuchianov Teleporters (IOI08_teleporters) C++14
75 / 100
601 ms 65536 KB
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <algorithm>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 1000000;
int edge[5 + 2 * nmax], seen[5 + nmax * 2];

int extract(int node) {
  int start = node;
  int _count = 0;
  do {
    seen[node] = 1;
    _count++;
    node = edge[node];
  } while(start != node);
  return _count;
}

int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);

  int n, m;
  std::cin >> n >> m;
  std::vector<std::pair<int,int>> points;
  points.push_back({0, 0});
  points.push_back({nmax * 2 + 1, 1});

  for(int i = 1;i <= n; i++) {
    int start, stop;
    std::cin >> start >> stop;
    points.push_back({start, i * 2});
    points.push_back({stop, i * 2 + 1});
  }
  std::sort(points.begin(), points.end());
  for(int i = 0; i < points.size() - 1; i++) 
    edge[points[i].second] = (points[i + 1].second ^ 1);
  int result = extract(0) - 1;
  std::vector<int> cycles;
  for(int i = 2; i <= 2 * n + 1; i++)
    if(seen[i] == 0)
      cycles.push_back(extract(i));
  std::sort(cycles.begin(), cycles.end());
  std::reverse(cycles.begin(), cycles.end());
  for(int i = 0; i < cycles.size() && i < m; i++)
    result += cycles[i];
  std::cout << result + m * 2;
  return 0;
}

Compilation message

teleporters.cpp: In function 'int main()':
teleporters.cpp:44:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |   for(int i = 0; i < points.size() - 1; i++)
      |                  ~~^~~~~~~~~~~~~~~~~~~
teleporters.cpp:53:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for(int i = 0; i < cycles.size() && i < m; i++)
      |                  ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 692 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1040 KB Output is correct
2 Correct 7 ms 1568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 7776 KB Output is correct
2 Correct 150 ms 18232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 18288 KB Output is correct
2 Incorrect 249 ms 32216 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 351 ms 49456 KB Output is correct
2 Correct 440 ms 64596 KB Output is correct
3 Correct 480 ms 65536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 589 ms 63632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 592 ms 65536 KB Output is correct
2 Correct 601 ms 65536 KB Output is correct
3 Correct 393 ms 65536 KB Output is correct
4 Correct 588 ms 65536 KB Output is correct