# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
54064 | 2018-07-02T09:34:57 Z | 강태규(#1453) | Teleporters (IOI08_teleporters) | C++11 | 1000 ms | 28540 KB |
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <unordered_map> #include <functional> #include <cstring> #include <cmath> #include <ctime> #include <cstdlib> using namespace std; typedef long long llong; typedef long double ld; typedef pair<int, int> pii; typedef pair<llong, llong> pll; int n, m; int s[1000000]; int e[1000000]; int comp[2000000]; int to[2000000]; bool visited[2000001]; int arr[2000000]; int find(int x) { int s = 0, e = n << 1; while (s <= e) { int m = (s + e) / 2; if (comp[m] == x) return m; if (comp[m] < x) s = m + 1; else e = m - 1; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 0; i < n; ++i) { cin >> s[i] >> e[i]; comp[i << 1 | 0] = s[i]; comp[i << 1 | 1] = e[i]; } comp[n << 1] = 0; sort(comp, comp + (n << 1 | 1)); for (int i = 0; i < n; ++i) { s[i] = find(s[i]); e[i] = find(e[i]); to[s[i]] = e[i]; to[e[i]] = s[i]; } visited[n << 1] = 1; int j = 0; for (int i = 0; i < (n << 1); ++i) { if (visited[i]) continue; int x = to[i + 1]; visited[i] = 1; arr[j] = 1; while (!visited[x]) { visited[x] = 1; x = to[x + 1]; ++arr[j]; } ++j; } int sz = arr[0]; sort(arr + 1, arr + j, greater<int>()); for (int i = 1; i < j && m > 0; ++i, --m) { sz += arr[i] + 2; } printf("%d\n", sz + ((m >> 1) << 2) + (m & 1)); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 416 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 524 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 524 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 568 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 612 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 616 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 616 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 616 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 616 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 616 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 740 KB | Output is correct |
2 | Correct | 11 ms | 868 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 868 KB | Output is correct |
2 | Correct | 9 ms | 996 KB | Output is correct |
3 | Correct | 20 ms | 1384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 1384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 1384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 108 ms | 4124 KB | Output is correct |
2 | Correct | 259 ms | 8700 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 171 ms | 8700 KB | Output is correct |
2 | Correct | 414 ms | 12668 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 603 ms | 18216 KB | Output is correct |
2 | Correct | 825 ms | 21832 KB | Output is correct |
3 | Correct | 744 ms | 24856 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 912 ms | 24856 KB | Output is correct |
2 | Correct | 982 ms | 26884 KB | Output is correct |
3 | Execution timed out | 1033 ms | 26884 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1075 ms | 28540 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |