Submission #556164

#TimeUsernameProblemLanguageResultExecution timeMemory
556164cheissmartRail (IOI14_rail)C++14
30 / 100
78 ms504 KiB
#include "rail.h"
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

void findLocation(int n, int fst_pos, int pos[], int tp[]) {
	for(int i = 0; i < n; i++) tp[i] = 0;

	int a = 0;
	pos[a] = fst_pos;
	tp[a] = 1; // down

	if(n == 1) return;

	vi da(n);
	for(int i = 0; i < n; i++) if(i != a)
		da[i] = getDistance(a, i);

	da[a] = INF;
	int b = int(min_element(ALL(da)) - da.begin());
	da[a] = 0;

	pos[b] = pos[a] + da[b];
	tp[b] = 2; // up

	vi db(n);
	for(int i = 0; i < n; i++) if(i != b)
		db[i] = getDistance(b, i);

	for(int i = 0; i < n; i++) if(i != b && db[i] < db[a]) {
		pos[i] = pos[b] - db[i];
		tp[i] = 1; // down
	}

	vi p(n); iota(ALL(p), 0);
	sort(ALL(p), [&] (int x, int y) {
		return da[x] < da[y];
	});
	int right_up = -1, left_down = -1;
	for(int i:p) if(tp[i] == 0) {
		if(da[i] - (pos[b] - pos[a]) < db[i]) { // right
			if(getDistance(i, a) == da[i]) { // up
				pos[i] = pos[a] + da[i];
				tp[i] = 2;
				right_up = i;
			} else { // down
				assert(right_up != -1);
				pos[i] = pos[right_up] - getDistance(right_up, i);
				tp[i] = 1;
			}
		} else { // left
			assert(da[i] - (pos[b] - pos[a]) == db[i]);
			if(getDistance(i, b) == db[i]) { // down
				pos[i] = pos[b] - db[i];
				tp[i] = 1;
				left_down = i;
			} else {
				assert(left_down != -1);
				pos[i] = pos[left_down] + getDistance(left_down, i);
				tp[i] = 2;
			}
		}
	}

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...