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