# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
95139 | Retro3014 | Teleporters (IOI08_teleporters) | C++17 | 532 ms | 29156 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
#define MAX_X 2000000
using namespace std;
typedef long long ll;
int N, M;
int r[MAX_X+1];
bool vst[MAX_X+1];
vector<int> cycle;
int ans;
void dfs(int x, ll y){
while(1){
if(vst[x]){
cycle.push_back(y);
return;
}
vst[x] = true;
if(x==MAX_X){
ans+=y;
return;
}
if(r[x]!=x+1) y++;
x = r[x];
}
}
int main(){
scanf("%d%d", &N, &M);
for(int i=0; i<MAX_X; i++) r[i] = i+1;
for(int i=0; i<N; i++){
int a, b; scanf("%d%d", &a, &b);
r[a-1] = b; r[b-1] = a;
}
for(int i=0; i<MAX_X; i++){
if(vst[i]) continue;
dfs(i, 0);
}
sort(cycle.begin(), cycle.end());
while(M--){
if(cycle.empty()){
cycle.push_back(1);
ans++;
}else{
ans+=2+cycle.back();
cycle.pop_back();
}
}
printf("%d", ans);
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... |