# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
98867 | shoemakerjo | Teleporters (IOI08_teleporters) | C++14 | 794 ms | 45160 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int N, M;
const int maxn = 2000010;
int aft[maxn];
int bef[maxn];
bool isin[maxn];
bool vis[maxn];
int a[maxn], b[maxn];
int previn[maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
fill(aft, aft+maxn, -1);
cin >> N >> M;
for (int i = 0; i < N; i++) {
cin >> a[i] >> b[i];
isin[a[i]] = true;
isin[b[i]] = true;
}
int cp = 0;
for (int i = 1; i < maxn; i++) {
if (isin[i]) {
previn[i] = cp;
cp = i;
}
}
for (int i = 0; i < N; i++) {
aft[previn[a[i]]] = b[i];
bef[b[i]] = previn[a[i]];
// cout << "thing: " << previn[a[i]] << " - " << b[i] <<
// " :: " << a[i] << endl;
aft[previn[b[i]]] = a[i];
bef[a[i]] = previn[b[i]];
}
isin[0] = true;
vector<int> cyclen;
int clen = 0;
for (int i = 0; i < maxn; i++) {
if (!isin[i] || vis[i]) continue;
int cv = 0;
int u = i;
bool ip = false;
// cout << " path: ";
while (!vis[u]) {
// cout << u << " ";
cv++;
vis[u] = true;
u = aft[u];
if (u == -1) {
ip = true;
clen = cv-1;
break;
}
}
// cout << u << endl;
if (!ip) cyclen.push_back(cv);
}
sort(cyclen.begin(), cyclen.end());
reverse(cyclen.begin(), cyclen.end());
// cout << "this: " << clen << endl;
for (int i = 0; i < cyclen.size(); i++) {
if (M == 0) break;
M--;
clen += cyclen[i] + 2;
}
if (M) {
int d2 = M/2;
if (M %2 == 1) clen++;
clen += d2 * 4;
}
cout << clen << endl;
}
컴파일 시 표준 에러 (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... |