Submission #396602

# Submission time Handle Problem Language Result Execution time Memory
396602 2021-04-30T11:59:00 Z Berted Teleporters (IOI08_teleporters) C++14
75 / 100
769 ms 28376 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <bitset>
#define pii pair<int, int>
#define fst first
#define snd second

using namespace std;

const int MX = 2000000;

int N, K, res = 0;
int nex[2000005];
pii A[2000005];
bitset<2000005> vis;
vector<int> cyc;

int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> N >> K;
	for (int i = 0; i < N; i++)
	{
		cin >> A[2 * i].fst >> A[2 * i].snd;
		A[2 * i + 1] = {A[2 * i].snd, A[2 * i].fst};
	}
	A[2 * N] = {0, 0}; A[2 * N + 1] = {MX + 1, -1};
	sort(A, A + 2 * N + 1);

	for (int i = 0; i < 2 * N + 2; i++)
	{
		if (A[i].snd != -1) nex[i] = upper_bound(A, A + 2 * N + 2, make_pair(A[i].snd, MX + 1)) - A;
		else nex[i] = -1;
	}

	int u = 0;
	while (u != -1) {res++; vis[u] = 1; u = nex[u];}

	for (int i = 0; i < 2 * N + 2; i++)
	{
		if (!vis[i])
		{
			u = i; int s = 0;
			while (!vis[u]) {vis[u] = 1; u = nex[u]; s++;}
			cyc.push_back(s);
		}
	}

	sort(cyc.begin(), cyc.end(), greater<int>());

	for (int i = 0; i < cyc.size() && i < K; i++) res += cyc[i];

	cout << res + 2 * K - 2 << "\n";
	return 0;
}

Compilation message

teleporters.cpp: In function 'int main()':
teleporters.cpp:52:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for (int i = 0; i < cyc.size() && i < K; i++) res += cyc[i];
      |                  ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 7 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 3680 KB Output is correct
2 Correct 218 ms 8004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 5960 KB Output is correct
2 Incorrect 343 ms 11596 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 417 ms 17212 KB Output is correct
2 Correct 535 ms 20312 KB Output is correct
3 Correct 444 ms 24032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 739 ms 23404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 769 ms 28376 KB Output is correct
2 Correct 752 ms 28216 KB Output is correct
3 Correct 546 ms 28076 KB Output is correct
4 Correct 549 ms 28260 KB Output is correct