Submission #1030994

#TimeUsernameProblemLanguageResultExecution timeMemory
1030994WarinchaiRoller Coaster Railroad (IOI16_railroad)C++14
0 / 100
393 ms28488 KiB
#include "railroad.h" #include<bits/stdc++.h> using namespace std; int p[2000005]; int fp(int a){ return p[a]==a?a:p[a]=fp(p[a]); } void un(int a,int b){ p[fp(a)]=fp(b); } vector<int>ids; map<int,int>mp; long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) { int n = (int) s.size(); vector<pair<int,int>>v; for(int i=0;i<n;i++){ v.push_back({s[i],1}); v.push_back({t[i],-1}); if(!mp[s[i]])ids.push_back(s[i]),mp[s[i]]++; if(!mp[t[i]])ids.push_back(t[i]),mp[t[i]]++; } sort(ids.begin(),ids.end()); sort(v.begin(),v.end()); for(int i=1;i<=mp.size();i++)p[i]=i; for(int i=0;i<n;i++){ un(lower_bound(ids.begin(),ids.end(),s[i])-ids.begin()+1,lower_bound(ids.begin(),ids.end(),t[i])-ids.begin()+1); } int val=0; for(int i=0;i<v.size();){ int sp=v[i].first; while(i<v.size()&&v[i].first==sp){ val+=v[i].second; i++; } if(val>1)return 1; else if(val==0)un(i+1,i+2); } for(int i=1;i<=mp.size();i++){ if(fp(i)!=fp(1))return 1; } return 0; }

Compilation message (stderr)

railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:24:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<int, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i=1;i<=mp.size();i++)p[i]=i;
      |                 ~^~~~~~~~~~~
railroad.cpp:29:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int i=0;i<v.size();){
      |                 ~^~~~~~~~~
railroad.cpp:31:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         while(i<v.size()&&v[i].first==sp){
      |               ~^~~~~~~~~
railroad.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<int, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i=1;i<=mp.size();i++){
      |                 ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...