結果

問題 No.2179 Planet Traveler
ユーザー 👑 kakel-sankakel-san
提出日時 2023-09-05 21:04:10
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 149 ms / 3,000 ms
コード長 2,422 bytes
コンパイル時間 1,298 ms
コンパイル使用メモリ 70,536 KB
実行使用メモリ 32,488 KB
最終ジャッジ日時 2023-09-05 21:04:17
合計ジャッジ時間 6,588 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
21,784 KB
testcase_01 AC 65 ms
21,696 KB
testcase_02 AC 65 ms
23,744 KB
testcase_03 AC 66 ms
21,644 KB
testcase_04 AC 66 ms
21,652 KB
testcase_05 AC 65 ms
21,832 KB
testcase_06 AC 66 ms
21,644 KB
testcase_07 AC 66 ms
21,704 KB
testcase_08 AC 67 ms
21,704 KB
testcase_09 AC 67 ms
21,720 KB
testcase_10 AC 66 ms
21,728 KB
testcase_11 AC 108 ms
30,236 KB
testcase_12 AC 111 ms
30,336 KB
testcase_13 AC 111 ms
30,268 KB
testcase_14 AC 136 ms
32,196 KB
testcase_15 AC 147 ms
32,204 KB
testcase_16 AC 142 ms
28,156 KB
testcase_17 AC 148 ms
30,268 KB
testcase_18 AC 148 ms
28,188 KB
testcase_19 AC 139 ms
30,136 KB
testcase_20 AC 73 ms
21,720 KB
testcase_21 AC 149 ms
32,488 KB
testcase_22 AC 103 ms
25,940 KB
testcase_23 AC 97 ms
23,648 KB
testcase_24 AC 132 ms
30,904 KB
testcase_25 AC 106 ms
23,644 KB
testcase_26 AC 128 ms
30,488 KB
testcase_27 AC 75 ms
23,740 KB
testcase_28 AC 93 ms
23,788 KB
testcase_29 AC 137 ms
30,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var n = NN;
        var map = NArr(n);

        var dp = new long[n][];
        for (var i = 0; i < n; ++i) dp[i] = new long[n];
        var tree = new List<(int to, long len)>[n];
        for (var i = 0; i < tree.Length; ++i) tree[i] = new List<(int to, long len)>();
        for (var i = 0; i < n; ++i) for (var j = i + 1; j < n; ++j)
        {
            if (map[i][2] == map[j][2])
            {
                var len = (long)(map[i][0] - map[j][0]) * (map[i][0] - map[j][0]) + (long)(map[i][1] - map[j][1]) * (map[i][1] - map[j][1]);
                dp[i][j] = len;
                dp[j][i] = len;
            }
            else
            {
                var a = (long)map[i][0] * map[i][0] + (long)map[i][1] * map[i][1];
                var b = (long)map[j][0] * map[j][0] + (long)map[j][1] * map[j][1];
                var len = a + b - SqrtFloor(4 * a * b);
                dp[i][j] = len;
                dp[j][i] = len;
            }
        }
        var ok = 3200000001L;
        var ng = -1L;
        while (ok - ng > 1)
        {
            var mid = (ok + ng) / 2;
            var q = new Queue<int>();
            q.Enqueue(0);
            var visited = new bool[n];
            visited[0] = true;
            while (q.Count > 0)
            {
                var cur = q.Dequeue();
                for (var i = 0; i < n; ++i)
                {
                    if (visited[i]) continue;
                    if (dp[cur][i] > mid) continue;
                    visited[i] = true;
                    q.Enqueue(i);
                }
            }
            if (visited[n - 1]) ok = mid;
            else ng = mid;
        }
        WriteLine(ok);
    }
    static long SqrtFloor(long a)
    {
        var sq = Math.Sqrt(a);
        for (var i = Math.Max(0, (long)sq - 10); i < sq + 10; ++i)
        {
            if (i * i <= a && a < (i + 1) * (i + 1)) return i;
        }
        return 0;
    }
}
0