답안 #917100

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
917100 2024-01-27T07:23:32 Z rxlfd314 철로 (IOI14_rail) C++17
30 / 100
310 ms 98908 KB
#include "rail.h"
#include <bits/stdc++.h>
using namespace std;
using ari2 = array<int, 2>;

#define vt vector
#define size(x) (int((x).size()))
#define all(x) begin(x), end(x)

#define REP(a, b, c, d) for (int a = (b); (d) > 0 ? a <= (c) : a >= (c); a += (d))
#define FOR(a, b, c) REP(a, b, c, 1)
#define ROF(a, b, c) REP(a, b, c, -1)

void findLocation(int N, int first, int location[], int stype[]) {
  FOR(i, 0, N-1)
    stype[i] = 0;
  location[0] = first;
  stype[0] = 1;
  if (N < 2)
    return;
  vt<vt<int>> D(N, vt<int>(N));
  FOR(i, 0, N-1)
    FOR(j, i+1, N-1) {
      D[i][j] = getDistance(i, j);
      D[j][i] = D[i][j];
    }
  int f[N];
  FOR(i, 0, N-1) {
    ari2 best = {INT_MAX, 0};
    FOR(j, 0, N-1)
      if (j != i)
        best = min(best, ari2{D[i][j], j});
    f[i] = best[1];
  }
  vt<int> adj[N];
  FOR(i, 0, N-1) {
    adj[i].push_back(f[i]);
    if (i != f[f[i]])
      adj[f[i]].push_back(i);
  }
  function<void(int)> dfs = [&](int i) {
    for (int j : adj[i]) {
      if (stype[j])
        continue;
      location[j] = location[i] + (stype[i] == 1 ? 1 : -1) * D[i][j];
      stype[j] = 3 - stype[i];
      dfs(j);
    }
  };
  dfs(0);
  FOR(i, 0, N-1) {
    if (stype[i])
      continue;
    int j = f[i];
    if (D[0][i] == D[0][f[0]] + D[f[0]][i]) { // to the left of 0
      if (D[0][i] > D[0][j]) { // i is 2
        stype[j] = 1;
        location[j] = location[f[0]] - D[f[0]][j];
        dfs(j);
      } else {
        stype[i] = 1;
        location[i] = location[f[0]] - D[f[0]][i];
        dfs(i);
      }
    } else {
      if (D[0][i] > D[0][j]) { // i is 1
        stype[j] = 2;
        location[j] = location[0] + D[0][j];
        dfs(j);
      } else {
        stype[i] = 2;
        location[i] = location[0] + D[0][i];
        dfs(i);
      }
    }
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 310 ms 98908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 295 ms 98888 KB Output isn't correct
2 Halted 0 ms 0 KB -