# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
990437 | AdamGS | Rail (IOI14_rail) | C++17 | 43 ms | 848 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 "rail.h"
#include<bits/stdc++.h>
using namespace std;
#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 INF=1e9+7;
set<int>C, D;
int odl(int a, int b, int x) {
if(C.find(b)!=C.end() && D.find(b)!=D.end()) return 0;
if(a<b) {
if(x==1) {
auto it=D.lower_bound(b);
int p=*it;
return p-a+p-b;
}
return b-a;
}
auto it=D.lower_bound(a);
int p=*it;
if(x==2) {
auto it=C.lower_bound(b); --it;
auto q=*it;
return p-a+p-q+b-q;
}
return p-a+p-b;
}
void findLocation(int n, int first, int location[], int stype[]) {
location[0]=first;
stype[0]=1;
if(n==1) return;
vector<int>P(n);
rep(i, n-1) P[i+1]=getDistance(0, i+1);
vector<pair<int,int>>V;
rep(i, n-1) V.pb({P[i+1], i+1});
sort(all(V));
location[V[0].nd]=location[0]+V[0].st;
stype[V[0].nd]=2;
C.insert(location[0]);
D.insert(location[V[0].nd]);
int a=0, b=V[0].nd;
for(int i=1; i<V.size(); ++i) {
int x=getDistance(V[i].nd, a), y=getDistance(V[i].nd, b);
if(odl(location[0], location[a]+x, 2)==V[i].st) {
location[V[i].nd]=location[a]+x;
stype[V[i].nd]=2;
D.insert(location[V[i].nd]);
if(location[V[i].nd]>location[b]) b=V[i].nd;
} else {
location[V[i].nd]=location[b]-x;
stype[V[i].nd]=1;
C.insert(location[V[i].nd]);
if(location[V[i].nd]<location[a]) a=V[i].nd;
}
}
}
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... |