# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
503591 | doowey | 철로 (IOI14_rail) | C++14 | 193 ms | 576 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>
#include "rail.h"
using namespace std;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
const int N = 5010;
int d[N];
bool calc[N];
void findLocation(int n, int first, int location[], int stype[]){
vector<pii> ord;
for(int i = 1; i < n; i ++ ){
d[i] = getDistance(0, i);
ord.push_back(mp(d[i], i));
}
sort(ord.begin(), ord.end());
location[0] = first;
stype[0] = 0;
calc[0]=true;
int ii = 0;
int jj;
int lef, rig;
int askl, askr;
int id;
int pos;
int dist;
bool valid;
int en, st;
for(int i = 0 ; i < ord.size(); i ++ ){
if(i == 0){
location[ord[i].se] = first + ord[i].fi;
stype[ord[i].se] = 1;
calc[ord[i].se] = true;
lef = first;
rig = location[ord[i].se];
jj = ord[i].se;
}
else{
id = ord[i].se;
askl = getDistance(ii, id);
askr = getDistance(jj, id);
// check whether pos is a valid one
pos = lef + askl;
valid = true;
// get distance between right and pos
dist = (int)1e9;
for(int j = 0 ; j < n; j ++ ){
if(calc[j]){
if(stype[j] == 0 && location[j] < pos && location[j] < rig){
dist = min(dist, rig - location[j] + pos - location[j]);
}
}
}
if(dist != askr) valid = false;
// get distance between 0 and pos
dist = (int)1e9;
if(pos > location[0]){
dist = pos - location[0];
}
else{
en = (int)1e9;
st = -(int)1e9;
for(int j = 0 ; j < n; j ++ ){
if(calc[i]){
if(stype[j] == 1 && location[j] > location[0]){
en = min(en, location[j]);
}
if(stype[j] == 0 && location[j] < pos){
st = max(st, location[j]);
}
}
}
dist = (en - location[0]) + (en - st) + (pos - st);
}
if(dist != d[id]) valid = false;
if(valid){
location[id] = pos;
stype[id] = 1;
if(location[id] > rig){
rig = location[id];
jj = id;
}
}
else{
location[id] = rig - askr;
stype[id] = 0;
if(location[id] < lef){
lef = location[id];
ii = id;
}
}
calc[id] = true;
}
}
cout << "------\n";
for(int i = 0 ; i < n; i ++ ){
cout << location[i] << " " << stype[i] << "\n";
stype[i] ++ ;
}
}
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... |