# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
772546 | kingfran1907 | Teleporters (IOI08_teleporters) | C++14 | 879 ms | 64052 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long llint;
const int maxn = 25e5+10;
const int inf = 0x3f3f3f3f;
int n, m;
int l[maxn], r[maxn];
vector< int > v;
vector< pair<int, int> > vs;
int nex[maxn];
bool bio[maxn];
priority_queue< int > cycles;
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
scanf("%d%d", l+i, r+i);
l[n] = -1;
r[n] = inf;
n++;
for (int i = 0; i < n; i++) {
v.push_back(l[i]);
v.push_back(r[i]);
}
sort(v.begin(), v.end());
for (int i = 0; i < n; i++) {
l[i] = lower_bound(v.begin(), v.end(), l[i]) - v.begin();
r[i] = lower_bound(v.begin(), v.end(), r[i]) - v.begin();
vs.push_back({l[i], i});
vs.push_back({r[i], i});
}
sort(vs.begin(), vs.end());
for (int i = 0; i < v.size() - 1; i++) {
int ind = vs[i + 1].second;
int rs = l[ind] + r[ind] - vs[i + 1].first;
nex[i] = rs;
}
int sol = 0;
for (int i = 0; i < v.size() - 1; i++) {
//printf("trying: %d\n", i);
if (bio[i]) continue;
int cnt = 0;
int ptr = i;
//printf("cycle: ");
while (!bio[ptr]) {
//printf("%d ", ptr);
bio[ptr] = true;
ptr = nex[ptr];
cnt++;
}
//printf("\n");
if (i > 0) cycles.push(cnt);
else sol = cnt - 1;
}
while (m && !cycles.empty()) {
//printf("debug: %d\n", cycles.top());
sol += cycles.top() + 2;
cycles.pop();
m--;
}
//printf("%d - %d\n", m, cycles.size());
m = m -= min(m, (int)cycles.size());
sol += 2 * (m - m % 2) + m % 2;
printf("%d\n", sol);
return 0;
}
컴파일 시 표준 에러 (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... |