제출 #30703

#제출 시각아이디문제언어결과실행 시간메모리
30703rondojim철로 (IOI14_rail)C++14
100 / 100
101 ms892 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); it++)
typedef long long ll;
typedef pair < int, int > ii;
 
const int inf = 1e9 + 333;
const ll linf = 1e18 + inf;
 
#include "rail.h"
 
const int N = 5000 + 5;
 
ii a[N];
 
void findLocation(int n, int first, int location[], int stype[]) {
	for(int i = 1; i < n; i++) {
		a[i].first = getDistance(0, i);
		a[i].second = i;
	}
	sort(a + 1, a + n);
	int second = a[1].second;
	location[0] = first;
	stype[0] = 1;
	location[second] = first + a[1].first;
	stype[second] = 2;
	int L = 0, R = second;
	set < int > sd, su;
	sd.insert(location[L]);
	su.insert(location[R]);
	for(int it = 2; it < n; it++) {
		int dist = a[it].first;
		int i = a[it].second;
		int distSecond = getDistance(second, i);
		if(dist == distSecond + a[1].first and location[second] - distSecond < first) {
			int distL = getDistance(L, i);
			int p = location[L] + distL;
			type(sd) it = sd.lower_bound(p);
			it--;
			int bef = *it;
			if(location[second] - bef + p - bef == distSecond) {
				location[i] = p;
				stype[i] = 2;
			}
			else {
				location[i] = location[second] - distSecond;
				stype[i] = 1;
				sd.insert(location[i]);
				L = i;
			}
		}
		else {
			int distR = getDistance(R, i);
			int p = location[R] - distR;
			type(su) it = su.upper_bound(p);
			int aft = *it;
			if(aft - first + aft - p == dist) {
				location[i] = p;
				stype[i] = 1;
			}
			else {
				location[i] = first + dist;
				stype[i] = 2;
				su.insert(location[i]);
				R = i;
			}
		}
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...