이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "railroad.h"
#include "bits/stdc++.h"
#define MAXN 400009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int par[MAXN],ata[MAXN];
int tap(int x){
if(ata[x]==x)return x;
return ata[x]=tap(ata[x]);
}
bool merge(int x,int y){
if((x=tap(x))==(y=tap(y)))return 0;
ata[y]=x;return 1;
}
long long plan_roller_coaster(vector<int> s, vector<int> t) {
int n = (int) s.size();
vector<int>v;v.pb(1);
for(int i=0;i<n;i++)
v.pb(s[i]),v.pb(t[i]);
sort(all(v));v.erase(unique(all(v)),v.end());
for(int i=1;i<=int(v.size());i++)ata[i]=i;
for(int i=0;i<n;i++){
s[i]=lower_bound(all(v),s[i])-v.begin();
t[i]=lower_bound(all(v),t[i])-v.begin();
s[i]++;t[i]++;
if(s[i]<t[i])
par[s[i]]++,par[t[i]]--;
if(s[i]>t[i])
par[t[i]]--,par[s[i]]++;
merge(s[i],t[i]);
}n=int(v.size());
merge(1,n);
par[1]--;int sum=0;
ll ans=0;
vector<pair<int,PII> >edge;
for(int i=1;i<n;i++){
sum+=par[i];
if(sum==0){
edge.pb(mp(v[i]-v[i-1],mp(i,i+1)));
continue;
}
merge(i,i+1);
if(sum>0)
ans+=sum*1LL*(v[i]-v[i-1]);
}
sort(all(edge));
tr(it,edge)
if(merge(it->ss.ff,it->ss.ss))
ans+=it->ff;
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:10:18: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
10 | #define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
| ^~~
railroad.cpp:62:5: note: in expansion of macro 'tr'
62 | tr(it,edge)
| ^~
railroad.cpp:65:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
65 | return ans;
| ^~~~~~
# | 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... |