# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
132376 | dragonslayerit | Teleporters (IOI08_teleporters) | C++14 | 1020 ms | 40548 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
int xs[2000005];
int ys[2000005];
bool vis[2000005];
int next[2000005];
int explore(int a){
int len=0;
while(!vis[a]){
vis[a]=true;
a=next[a];
len++;
}
return len;
}
int main(){
int N,M;
scanf("%d %d",&N,&M);
for(int i=0;i<N;i++){
scanf("%d %d",&xs[i<<1],&xs[i<<1|1]);
}
std::copy(xs,xs+N*2,ys);
std::sort(ys,ys+N*2);
for(int i=0;i<N*2;i+=2){
int a=std::lower_bound(ys,ys+N*2,xs[i])-ys;
int b=std::lower_bound(ys,ys+N*2,xs[i^1])-ys;
next[a]=b+1;
next[b]=a+1;
}
vis[N*2]=true;
int score=explore(0);
std::vector<int> cycles;
for(int i=1;i<N*2;i++){
if(!vis[i]){
cycles.push_back(explore(i));
}
}
std::sort(cycles.begin(),cycles.end());
while(M>0&&cycles.size()){
score+=cycles.back()+2;
cycles.pop_back();
M--;
}
printf("%d\n",score+M/2*4+M%2);
return 0;
}
Compilation message (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... |