제출 #575338

#제출 시각아이디문제언어결과실행 시간메모리
575338Theo830철로 (IOI14_rail)C++17
30 / 100
75 ms716 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
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;
    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];
        if(getDistance(last,x.S) == A){
            location[x.S] = location[last] - A;
            stype[x.S] = 1;
        }
        else{
            location[x.S] = location[last] + A;
            stype[x.S] = 2;
            last = x.S;
        }
    }
    last = 0;
    for(auto x:left){
        ll A = x.F - dist2[last];
        if(getDistance(last,x.S) == A){
            location[x.S] = location[last] + A;
            stype[x.S] = 2;
        }
        else{
            location[x.S] = location[last] - A;
            stype[x.S] = 1;
            last = x.S;
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...