# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
827591 | tolbi | Roller Coaster Railroad (IOI16_railroad) | C++17 | 73 ms | 9708 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#include "railroad.h"
mt19937 ayahya(chrono::high_resolution_clock().now().time_since_epoch().count());
long long plan_roller_coaster(vector<int> s, vector<int> t) {
vector<pair<int,pair<int,int>>> arr;
for (int i = 0; i < s.size(); i++){
if (s[i]==t[i]) continue;
int c = 1;
if (s[i]>=t[i]){
c=-1;
}
arr.push_back({min(s[i],t[i]),{c,1}});
arr.push_back({max(s[i],t[i])+1,{-c,0}});
}
sort(arr.begin(), arr.end());
ll crr = -1;
ll crr2 = 0;
int n = arr.size();
ll ans = 0;
for (int i = 0; i < n; i++){
if (i<n-1 && arr[i].first==arr[i+1].first){
crr+=arr[i].second.first;
crr2+=arr[i].second.second;
continue;
}
crr+=arr[i].second.first;
crr2+=arr[i].second.second;
if (crr>0){
ans+=crr*(arr[i+1].first-arr[i].first);
}
if (crr2==0 && i < n-1){
ans+=arr[i+1].first-arr[i].first;
}
}
return ans;
}
Compilation message (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... |