Submission #424980

#TimeUsernameProblemLanguageResultExecution timeMemory
424980MarcoMeijerRail (IOI14_rail)C++14
0 / 100
110 ms34244 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(), e.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] = 1;
  location[u] = first + getD(0,u);

  REP(i,1,n) {
    if(i == u) continue;
    int a = getD(0,i);
    int b = getD(u,i);
    if(a < b) {
      // i is on the right side of 0
      stype[i] = 2;
      location[i] = location[0] - getD(0,i);
    } else {
      // i is on the left side of 0
      stype[i] = 1;
      location[i] = location[u] - getD(u,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...