# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
396607 | Berted | Teleporters (IOI08_teleporters) | C++14 | 732 ms | 38864 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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[MX + 5];
pii A[MX + 5];
bitset<MX + 5> 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 + 2);
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() && K > 0; i++, K--) res += cyc[i] + 2;
cout << res + 4 * (K / 2) + (K % 2) - 2 << "\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |