이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "railroad.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=4e5+7, INF=1e9+7;
vector<int>skal;
map<int,int>mp;
int F[LIM], akt;
int fnd(int x) {
if(F[x]==x) return x;
return F[x]=fnd(F[x]);
}
void uni(int a, int b) {
if(fnd(a)==fnd(b)) return;
F[fnd(b)]=fnd(a);
}
ll plan_roller_coaster(vector<int>s, vector<int>t) {
s.pb(INF);
t.pb(0);
int n=s.size();
for(auto i : s) skal.pb(i);
for(auto i : t) skal.pb(i);
sort(all(skal));
for(auto i : skal) if(mp.find(i)==mp.end()) mp[i]=akt++;
rep(i, akt) F[i]=i;
vector<pair<int,int>>P;
rep(i, n) {
P.pb({s[i], -1});
P.pb({t[i], 1});
}
sort(all(P));
int lst=P[0].st;
ll sum=0;
for(auto i : P) {
if(i.st!=lst) {
if(sum<0) return 1;
if(sum>0) uni(mp[i.st], mp[lst]);
}
sum+=i.nd;
lst=i.st;
}
rep(i, n) uni(mp[s[i]], mp[t[i]]);
rep(i, akt) if(fnd(i)!=fnd(0)) return 1;
return 0;
}
# | 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... |