Submission #254263

#TimeUsernameProblemLanguageResultExecution timeMemory
254263PedroBigManRail (IOI14_rail)C++14
56 / 100
594 ms196728 KiB
#include "rail.h"
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <list>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
#include <cstring>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=(ll) a; i<(ll) b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define whole(x) x.begin(),x.end()
#define DEBUG(i) cout<<"Pedro Is The Master "<<i<<endl
#define INF 500000000LL
#define EPS 0.00000001
#define pi 3.14159

template<class A=ll> 
void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;}

void findLocation(int N, int first, int pos[], int typ[])
{
    if(N==1) {pos[0]=first; typ[0]=1; return;}
    pos[0]=first; typ[0]=1;
    vector<vector<ll> > d; vector<ll> xx; REP(i,0,N) {xx.pb(-1LL);} REP(i,0,N) {d.pb(xx);}
    REP(i,0,N) 
    {
        REP(j,0,i) {d[i][j]=getDistance(i,j);}
    }
    REP(i,0,N) {d[i][i]=INF;}
    REP(i,0,N) {REP(j,i+1,N) {d[i][j]=d[j][i];}}
    vector<ll> close; 
    REP(i,0,N) 
    {
        close.pb((ll) (min_element(whole(d[i]))-d[i].begin()));
    }
    
    REP(i,0,N) {d[i][i]=0;}
    ll cr = close[0]; ll cl=close[cr];
    pos[cr]=pos[0]+d[0][cr]; pos[cl]=pos[cr]-d[cl][cr];
    typ[cl]=1; typ[cr]=2;
    vector<bool> isclose; REP(i,0,N) {isclose.pb(false);}
    REP(i,0,N) {isclose[close[i]]=true;}
    REP(i,0,N) 
    {
        if(i==cl || i==cr) {continue;}
        if(!isclose[i]) {continue;}
        bool left=false;
        if(d[i][cl] > d[i][cr]) {left=true;}
        ll j = close[i];
        if(left)
        {
            if(j==cr)
            {
                typ[i]=1;
                pos[i]=pos[cr]-d[i][cr];
            }
            else if(d[i][cr]<d[j][cr]) 
            {
                typ[i]=1;
                pos[i]=pos[cr]-d[i][cr];
            } 
            else 
            {
                typ[i]=2;
                pos[i]=pos[cr]-d[j][cr]+d[i][j];
            }
        }
        else
        {
            if(j==cl)
            {
                typ[i]=2;
                pos[i]=pos[cl]+d[i][cl];
            }
            else if(d[i][cl]<d[j][cl])
            {
                typ[i]=2;
                pos[i]=pos[cl]+d[i][cl];
            }
            else
            {
                typ[i]=1;
                pos[i]=pos[cl]+d[j][cl]-d[i][j];
            }
        }
    }
    REP(i,0,N)
    {
        if(isclose[i] || i==cl || i==cr) {continue;}
        bool left=false;
        if(d[i][cl] > d[i][cr]) {left=true;}
        ll j = close[i];
        if(typ[j]==1) {typ[i]=2;} else {typ[i]=1;}
        if(left)
        {
            if(typ[i]==1) {pos[i]=pos[cr]-d[i][cr];}
            else {pos[i]=pos[cr]-d[cr][j]+d[i][j];}
        }
        else
        {
            if(typ[i]==1) {pos[i]=pos[cl]+d[j][cl]-d[i][j];}
            else {pos[i]=pos[cl]+d[i][cl];}
        }
    }
    return;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...