Submission #132378

#TimeUsernameProblemLanguageResultExecution timeMemory
132378dragonslayeritTeleporters (IOI08_teleporters)C++14
100 / 100
995 ms44644 KiB
#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)); } } if(M<cycles.size()){ std::nth_element(cycles.begin(),cycles.end()-M,cycles.end()); } 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)

teleporters.cpp: In function 'int main()':
teleporters.cpp:45:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(M<cycles.size()){
      ~^~~~~~~~~~~~~~
teleporters.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&N,&M);
   ~~~~~^~~~~~~~~~~~~~~
teleporters.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&xs[i<<1],&xs[i<<1|1]);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...