제출 #49562

#제출 시각아이디문제언어결과실행 시간메모리
49562khsoo01철로 (IOI14_rail)C++11
100 / 100
127 ms32252 KiB
#include "rail.h" #include<bits/stdc++.h> using namespace std; const int M = 5005, inf = 1e9; int d[M][M]; map<int,int> inv; int getd (int I, int J) { if(I == J) return 0; if(I > J) swap(I, J); if(!d[I][J]) d[I][J] = getDistance(I, J); return d[I][J]; } void solve (int L[], int S[], vector<int> &X, int P, int Q) { sort(X.begin(), X.end(), [&](int A, int B) { return getd(P, A) < getd(P, B); }); int D = 1 - 2 * (S[P] == 1); for(auto &T : X) { int V = (getd(Q, T) + getd(P, Q) - getd(P, T)) / 2; int C = L[Q] + D * V; if(inv[C] == S[Q]) { L[T] = C + D * (getd(P, T) - abs(L[P] - C)); S[T] = S[P]; } else { L[T] = L[P] - D * getd(P, T); S[T] = S[Q]; Q = T; } inv[L[T]] = S[T]; } } void findLocation(int N, int F, int L[], int S[]) { L[0] = F; S[0] = 1; inv[L[0]] = 1; if(N == 1) return; int I = 1; for(int i=2;i<N;i++) { if(getd(0, I) > getd(0, i)) I = i; } L[I] = L[0] + getd(0, I); S[I] = 2; inv[L[I]] = 2; vector<int> X, Y; for(int i=1;i<N;i++) { if(i == I) continue; if(getd(I, i) + getd(I, 0) == getd(0, i)) { if(getd(I, 0) > getd(I, i)) { L[i] = L[0] + getd(I, 0) - getd(I, i); S[i] = 1; inv[L[i]] = 1; } else X.push_back(i); } else Y.push_back(i); } solve(L, S, X, I, 0); solve(L, S, Y, 0, 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...