Submission #575346

#TimeUsernameProblemLanguageResultExecution timeMemory
575346Theo830Rail (IOI14_rail)C++17
30 / 100
73 ms724 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e9+7; ll MOD = 998244353; typedef pair<ll,ll> ii; #define iii pair<ii,ll> #define f(i,a,b) for(ll i = a;i < b;i++) #define pb push_back #define vll vector<ll> #define F first #define S second #define all(x) (x).begin(), (x).end() ///I hope I will get uprating and don't make mistakes ///I will never stop programming ///sqrt(-1) Love C++ ///Please don't hack me ///@TheofanisOrfanou Theo830 ///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst) ///Stay Calm ///Look for special cases ///Beware of overflow and array bounds ///Think the problem backwards ///Training #include "rail.h" void findLocation(int n, int first, int location[], int stype[]){ location[0] = first; stype[0] = 1; if(n == 1){ return; } ll dist[n] = {0}; ll dist2[n] = {0}; vector<ii>arr; f(i,1,n){ dist[i] = getDistance(0,i); arr.pb(ii(dist[i],i)); } sort(all(arr)); ll D = arr[0].S; location[D] = first + arr[0].F; stype[D] = 2; f(i,0,n){ if(i != D){ dist2[i] = getDistance(D,i); } } vector<ii>left,right; f(i,1,n){ if(i != D){ if(dist[i] < dist2[i]){ right.pb(ii(dist[i],i)); } else{ left.pb(ii(dist2[i],i)); } } } sort(all(left)); sort(all(right)); ll last = D; for(auto x:right){ ll A = x.F - dist[last]; ll posa = getDistance(last,x.S); if(posa > A){ location[x.S] = location[last] + A; stype[x.S] = 2; last = x.S; } else{ location[x.S] = location[last] - posa; stype[x.S] = 1; } } last = 0; for(auto x:left){ ll A = x.F - dist2[last]; ll posa = getDistance(last,x.S); if(posa > A){ location[x.S] = location[last] - A; stype[x.S] = 1; last = x.S; } else{ location[x.S] = location[last] + posa; stype[x.S] = 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...