# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
77216 | shoemakerjo | Roller Coaster Railroad (IOI16_railroad) | C++14 | 1459 ms | 85080 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "railroad.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define maxv 400010
#define mp make_pair
vector<ll> nums;
vector<int> adj[maxv];
int par[maxv];
const int inf = 1000000010;
int findset(int u) {
if (par[u] == u) return u;
return par[u] = findset(par[u]);
}
void unionset(int u, int v) {
u = findset(u);
v = findset(v);
if (u != v) {
if (rand() % 2) { //lazy dsu
par[u] = v;
}
else par[v] = u;
}
}
map<ll, int> indo;
int delt[maxv];
ll plan_roller_coaster(vector<int> s, vector<int> t) {
srand(23);
int n = (int) s.size();
set<int> og;
for (int v : s) og.insert(v);
for (int v : t) og.insert(v);
og.insert(1);
og.insert(inf);
for (int v : og) nums.push_back(v);
for (int i = 0; i < nums.size(); i++) {
indo[nums[i]] = i;
par[i] = i; //setting up the dsu for later
}
// cout << "here 1" << endl;
for (int i = 0; i < s.size(); i++) {
adj[indo[s[i]]].push_back(indo[t[i]]);
// cout << s[i] << " to " << t[i] << " is: " << endl;
// cout << " " << indo[s[i]] << " to " << indo[t[i]] << endl;
}
adj[indo[inf]].push_back(indo[1]);
// cout << "last guy is " << indo[inf] << " to " << indo[1] << endl;
ll ans = 0LL;
// cout << "here 2 " << endl;
for (int i = 0; i < nums.size(); i++) {
for (int v : adj[i]) {
delt[i]++;
delt[v]--;
}
}
// cout << "here 3" << endl;
int curval = 0;
for (int i = 0; i < nums.size()-1; i++) {
curval += delt[i];
// cout << i << " " << nums[i] << " : " << curval << endl;
// cout << " " << delt[i] << endl;
if (curval > 0) {
// cout << i << " is positive! " << endl;
ans += curval * 1LL * (nums[i]-nums[i-1]);
adj[i+1].push_back(i);
}
else if (curval < 0) {
adj[i].push_back(i+1);
}
}
vector<pair<ll, int>> edges;
//the first is the lenght, the second is the starting guy
for (int i = 0; i < nums.size()-1; i++) {
edges.push_back(mp(nums[i+1]-nums[i], i));
}
sort(edges.begin(), edges.end());
for (int i = 0; i < nums.size(); i++) {
for (int v : adj[i]) unionset(i, v);
}
for (int i = 0; i < edges.size(); i++) {
if (findset(edges[i].second) != findset(edges[i].second+1)) {
unionset(edges[i].second, edges[i].second+1);
ans += edges[i].first;
}
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |