結果

問題 No.94 圏外です。(EASY)
ユーザー 👑 kakel-sankakel-san
提出日時 2023-10-21 20:44:21
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 112 ms / 5,000 ms
コード長 4,724 bytes
コンパイル時間 7,526 ms
コンパイル使用メモリ 157,508 KB
実行使用メモリ 177,784 KB
最終ジャッジ日時 2023-10-21 20:44:36
合計ジャッジ時間 11,414 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
32,892 KB
testcase_01 AC 85 ms
32,544 KB
testcase_02 AC 98 ms
32,892 KB
testcase_03 AC 88 ms
32,424 KB
testcase_04 AC 101 ms
33,744 KB
testcase_05 AC 102 ms
33,792 KB
testcase_06 AC 103 ms
33,848 KB
testcase_07 AC 108 ms
33,936 KB
testcase_08 AC 111 ms
34,040 KB
testcase_09 AC 112 ms
34,168 KB
testcase_10 AC 111 ms
34,160 KB
testcase_11 AC 110 ms
34,168 KB
testcase_12 AC 110 ms
34,168 KB
testcase_13 AC 112 ms
34,160 KB
testcase_14 AC 111 ms
34,176 KB
testcase_15 AC 111 ms
34,160 KB
testcase_16 AC 111 ms
34,176 KB
testcase_17 AC 110 ms
34,152 KB
testcase_18 AC 109 ms
34,168 KB
testcase_19 AC 110 ms
34,068 KB
testcase_20 AC 95 ms
32,900 KB
testcase_21 AC 83 ms
177,784 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (101 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

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);
        if (n == 0)
        {
            WriteLine(1);
            return;
        }
        Array.Sort(map, (l, r) => l[0].CompareTo(r[0]));
        var dic = new Dictionary<int, int>();
        for (var i = 0; i < n; ++i)
        {
            dic[Key(map[i][0], map[i][1])] = i;
        }
        var uf = new UnionFindTree(n);
        for (var i = 0; i < n; ++i)
        {
            for (var dx = 0; dx <= 10; ++dx) for (var dy = 0; dy <= 10; ++dy)
            {
                if (dx * dx + dy * dy > 100) break;
                var key = Key(map[i][0] + dx, map[i][1] + dy);
                if (dic.ContainsKey(key)) uf.Unite(i, dic[key]);
                key = Key(map[i][0] + dx, map[i][1] - dy);
                if (dic.ContainsKey(key)) uf.Unite(i, dic[key]);
            }
        }
        var lists = new List<int[]>[n];
        for (var i = 0; i < lists.Length; ++i) lists[i] = new List<int[]>();
        for (var i = 0; i < n; ++i) lists[uf.GetRoot(i)].Add(map[i]);
        var ans = 0;
        for (var i = 0; i < n; ++i)
        {
            if (lists[i].Count > 1)
            {
                var ch = MakeConvexHull(lists[i]);
                for (var j = 0; j < ch.Count; ++j) for (var k = j + 1; k < ch.Count; ++k)
                {
                    var p = lists[i][ch[j]];
                    var q = lists[i][ch[k]];
                    ans = Math.Max(ans, (p[0] - q[0]) * (p[0] - q[0]) + (p[1] - q[1]) * (p[1] - q[1]));
                }
            }
        }
        WriteLine(Math.Sqrt(ans) + 2);
    }
    static int Key(int x, int y)
    {
        return x * 100000 + y;
    }
    class UnionFindTree
    {
        int[] roots;
        public UnionFindTree(int size)
        {
            roots = new int[size];
            for (var i = 0; i < size; ++i) roots[i] = -1;
        }
        public int GetRoot(int a)
        {
            if (roots[a] < 0) return a;
            return roots[a] = GetRoot(roots[a]);
        }
        public bool IsSameTree(int a, int b)
        {
            return GetRoot(a) == GetRoot(b);
        }
        public bool Unite(int a, int b)
        {
            var x = GetRoot(a);
            var y = GetRoot(b);
            if (x == y) return false;
            if (-roots[x] < -roots[y]) { var tmp = x; x = y; y = tmp; }
            roots[x] += roots[y];
            roots[y] = x;
            return true;
        }
        public int GetSize(int a)
        {
            return -roots[GetRoot(a)];
        }
    }
    static List<int> MakeConvexHull(List<int[]> _map)
    {
        var map = _map.Select((xy, id) => (xy, id)).ToList();
        map.Sort((l, r) =>
        {
            var d = l.xy[0].CompareTo(r.xy[0]);
            if (d != 0) return d;
            return l.xy[1].CompareTo(r.xy[1]);
        });
        var dn = new List<(int[] xy, int id)>();
        dn.Add(map[0]);
        for (var i = 1; i < map.Count; ++i)
        {
            while (dn.Count > 1)
            {
                var p2 = dn[dn.Count - 2].xy;
                var p1 = dn[dn.Count - 1].xy;
                if (OuterProduct(p1[0] - p2[0], p1[1] - p2[1], map[i].xy[0] - p1[0], map[i].xy[1] - p1[1]) <= 0)
                {
                    dn.RemoveAt(dn.Count - 1);
                }
                else break;
            }
            dn.Add(map[i]);
        }
        var up = new List<(int[] xy, int id)>();
        up.Add(map[map.Count - 1]);
        for (var i = map.Count - 2; i >= 0; --i)
        {
            while (up.Count > 1)
            {
                var p2 = up[up.Count - 2].xy;
                var p1 = up[up.Count - 1].xy;
                if (OuterProduct(p1[0] - p2[0], p1[1] - p2[1], map[i].xy[0] - p1[0], map[i].xy[1] - p1[1]) <= 0)
                {
                    up.RemoveAt(up.Count - 1);
                }
                else break;
            }
            up.Add(map[i]);
        }
        dn.AddRange(up.Skip(1).Take(up.Count - 2));
        return dn.Select(li => li.id).ToList();
    }
    static long OuterProduct(int ax, int ay, int bx, int by)
    {
        return (long)ax * by - (long)ay * bx;
    }
}
0