제출 #425159

#제출 시각아이디문제언어결과실행 시간메모리
425159MarcoMeijer철로 (IOI14_rail)C++14
30 / 100
300 ms34308 KiB
#include "rail.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef vector<ll> vll; typedef vector<int> vi; typedef vector<ii> vii; #define REP(a,b,c) for(int a=int(b); a<int(c); a++) #define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--) #define RE(a,b) REP(a,0,b) #define RE1(a,b) REP(a,1,b+1) #define FOR(a,b) for(auto& a : b) #define pb push_back #define fi first #define se second #define all(a) a.begin(),a.end() const int MX = 6000; void findLocation(int n, int first, int location[], int stype[]) { auto getD = [](int u, int v) { static int mem[MX][MX]; if(u == v) return 0; if(mem[u][v] != 0) return mem[u][v]; return mem[u][v] = mem[v][u] = getDistance(u,v); }; int closest = 1e9; REP(i,1,n) closest = min(closest, getD(0,i)); int u = -1; REP(i,1,n) if(getD(0,i) == closest) u = i; stype [0] = 1; location[0] = first; stype [u] = 2; location[u] = first + getD(0,u); vii pq; REP(i,1,n) { if(i == u) continue; int a = getD(i,0); pq.pb({a,i}); } sort(all(pq)); int L=0, R=u; FOR(p,pq) { int i=p.se; int dli = getD(L,i); int dri = getD(R,i); int d0i = getD(0,i); bool possible; int posl = location[R] - dri; int posr = location[L] + dli; int expected = 0; // case: ( ( ) ) // L 0 R i possible = true; if(posr <= location[R]) possible = false; if(posr != location[0] + d0i) possible = false; expected = 1e9; RE(j,n) if(stype[j] == 1) expected = min(expected, abs(location[j]-posr) + abs(location[j]-location[R])); if(dri != expected) possible = false; if(possible) { stype[i] = 2; location[i] = posr; continue; } // case: ( ) ( ) // L i 0 R possible = true; if(posr >= location[0]) possible = false; expected = 1e9; RE(j,n) if(stype[j] == 1) if(location[j] < posr) expected = min(expected, abs(location[j]-posr) + abs(location[j]-location[0])); if(d0i != expected) possible = false; expected = 1e9; RE(j,n) if(stype[j] == 1) if(location[j] < posr) expected = min(expected, abs(location[j]-posr) + abs(location[j]-location[R])); if(dri != expected) possible = false; if(possible) { stype[i] = 2; location[i] = posr; continue; } // case: ( ( ( ) // i L 0 R // case: ( ( ( ) // L 0 i R stype[i] = 1; location[i] = posl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...