Submission #496940

#TimeUsernameProblemLanguageResultExecution timeMemory
496940TemmieRail (IOI14_rail)C++17
0 / 100
77 ms8784 KiB
#include "rail.h"
#include <bits/stdc++.h>

//int getDistance(int i, int j) {
	//return 0;
//}

void findLocation(int n, int first, int location[], int stype[]) {
	location[0] = first, stype[0] = 1;
	std::vector <int> inv(int(1e6) + 3, -1);
	inv[first] = 0;
	if (n == 1) {
		return;
	}
	std::vector <std::pair <int, int>> a(n - 1);
	for (int i = 1; i < n; i++) {
		a[i - 1] = { getDistance(0, i), i };
	}
	std::sort(a.rbegin(), a.rend());
	int l = first, r = a.back().second;
	location[r] = first + a.back().first;
	stype[r] = 2;
	inv[location[r]] = r;
	a.pop_back();
	while (a.size()) {
		int ind = a.back().second;
		a.pop_back();
		int left = getDistance(l, ind);
		int right = getDistance(r, ind);
		int loc1 = location[l] + left;
		int loc2 = location[r] - right;
		int mid =(loc1 + loc2) >> 1;
		if (inv[mid] != -1) {
			stype[ind] = stype[inv[mid]] == 1 ? 2 : 1;
		} else if (first < mid) {
			stype[ind] = 2;
		} else {
			stype[ind] = 1;
		}
		if (stype[ind] == 1) {
			std::swap(loc1, loc2);
		}
		location[ind] = loc1;
		inv[location[ind]] = ind;
		if (loc1 > location[r]) {
			r = loc1;
		} else if (loc1 < location[l]) {
			l = loc2;
		}
	}
}

//int main() {
	
//}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...