結果

問題 No.2179 Planet Traveler
ユーザー 👑 chro_96chro_96
提出日時 2023-01-06 22:53:57
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 33 ms / 3,000 ms
コード長 1,638 bytes
コンパイル時間 1,047 ms
コンパイル使用メモリ 30,120 KB
実行使用メモリ 6,968 KB
最終ジャッジ日時 2023-08-20 16:17:49
合計ジャッジ時間 2,340 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,856 KB
testcase_01 AC 2 ms
6,876 KB
testcase_02 AC 2 ms
6,868 KB
testcase_03 AC 3 ms
6,964 KB
testcase_04 AC 2 ms
6,936 KB
testcase_05 AC 2 ms
6,968 KB
testcase_06 AC 2 ms
6,912 KB
testcase_07 AC 2 ms
6,760 KB
testcase_08 AC 2 ms
6,800 KB
testcase_09 AC 2 ms
6,916 KB
testcase_10 AC 2 ms
6,860 KB
testcase_11 AC 7 ms
6,832 KB
testcase_12 AC 33 ms
6,800 KB
testcase_13 AC 31 ms
6,848 KB
testcase_14 AC 6 ms
6,832 KB
testcase_15 AC 5 ms
6,804 KB
testcase_16 AC 6 ms
6,804 KB
testcase_17 AC 31 ms
6,940 KB
testcase_18 AC 28 ms
6,900 KB
testcase_19 AC 27 ms
6,924 KB
testcase_20 AC 6 ms
6,924 KB
testcase_21 AC 27 ms
6,856 KB
testcase_22 AC 19 ms
6,876 KB
testcase_23 AC 16 ms
6,912 KB
testcase_24 AC 24 ms
6,876 KB
testcase_25 AC 19 ms
6,952 KB
testcase_26 AC 26 ms
6,860 KB
testcase_27 AC 6 ms
6,900 KB
testcase_28 AC 14 ms
6,872 KB
testcase_29 AC 25 ms
6,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main () {
  int n = 0;
  long long x[800] = {};
  long long y[800] = {};
  int t[800] = {};
  
  int res = 0;
  
  long long e[800][800] = {};
  long long d[800] = {};
  
  int v = 0;
  int used[800] = {};
  
  res = scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    res = scanf("%lld", x+i);
    res = scanf("%lld", y+i);
    res = scanf("%d", t+i);
  }
  
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (t[i] == t[j]) {
        long long diff_x = x[i]-x[j];
        long long diff_y = y[i]-y[j];
        long long dist = diff_x*diff_x+diff_y*diff_y;
        e[j][i] = dist;
        e[i][j] = dist;
      } else {
        long long a = x[i]*x[i]+y[i]*y[i];
        long long b = x[j]*x[j]+y[j]*y[j];
        long long s[2] = { -1LL, a+b };
        while (s[1]-s[0] > 1LL) {
          long long nxt = (s[0]+s[1])/2LL;
          long long tmp = a+b-nxt;
          if (tmp*tmp > 4LL*a*b) {
            s[0] = nxt;
          } else {
            s[1] = nxt;
          }
        }
        e[j][i] = s[1];
        e[i][j] = s[1];
      }
    }
  }
  
  for (int i = 0; i < n; i++) {
    d[i] = 1000000000000000000LL;
  }
  
  d[0] = 0LL;
  v = 0;
  while (v >= 0) {
    long long min = 1000000000000000000LL;
    used[v] = 1;
    for (int i = 0; i < n; i++) {
      long long max = d[v];
      if (max < e[v][i]) {
        max = e[v][i];
      }
      if (d[i] > max) {
        d[i] = max;
      }
    }
    v = -1;
    for (int i = 0; i < n; i++) {
      if (used[i] <= 0 && d[i] < min) {
        v = i;
        min = d[i];
      }
    }
  }
  
  printf("%lld\n", d[n-1]);
  return 0;
}
0