제출 #1031025

#제출 시각아이디문제언어결과실행 시간메모리
1031025WarinchaiRoller Coaster Railroad (IOI16_railroad)C++14
30 / 100
125 ms12992 KiB
#include "railroad.h" #include<bits/stdc++.h> using namespace std; int p[2000005],a[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<int> ids; for(int i=0;i<n;i++){ ids.push_back(s[i]); ids.push_back(t[i]); } sort(ids.begin(),ids.end()); ids.erase(unique(ids.begin(),ids.end()),ids.end()); int m=ids.size(); for(int i=1;i<=m;i++)p[i]=i; for(int i=0;i<n;i++){ s[i]=lower_bound(ids.begin(),ids.end(),s[i])-ids.begin()+1; t[i]=lower_bound(ids.begin(),ids.end(),t[i])-ids.begin()+1; un(s[i],t[i]); a[s[i]]++,a[t[i]]--; } int val=0; for(int i=1;i<m;i++){ val+=a[i]; if(val>1)return 1; else if(val<1)un(i,i+1); } for(int i=1;i<=m;i++){ if(fp(i)!=fp(1))return 1; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...