結果

問題 No.96 圏外です。
ユーザー 👑 kakel-sankakel-san
提出日時 2023-10-21 20:37:12
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 1,494 ms / 5,000 ms
コード長 4,724 bytes
コンパイル時間 16,425 ms
コンパイル使用メモリ 158,148 KB
実行使用メモリ 207,212 KB
最終ジャッジ日時 2023-10-21 20:37:51
合計ジャッジ時間 26,259 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
33,212 KB
testcase_01 AC 79 ms
32,864 KB
testcase_02 AC 89 ms
33,212 KB
testcase_03 AC 80 ms
32,716 KB
testcase_04 AC 111 ms
34,976 KB
testcase_05 AC 123 ms
35,684 KB
testcase_06 AC 151 ms
36,620 KB
testcase_07 AC 172 ms
38,820 KB
testcase_08 AC 219 ms
40,040 KB
testcase_09 AC 237 ms
42,656 KB
testcase_10 AC 346 ms
46,976 KB
testcase_11 AC 411 ms
48,828 KB
testcase_12 AC 454 ms
48,716 KB
testcase_13 AC 627 ms
54,284 KB
testcase_14 AC 742 ms
55,208 KB
testcase_15 AC 822 ms
59,748 KB
testcase_16 AC 1,031 ms
64,456 KB
testcase_17 AC 1,299 ms
71,132 KB
testcase_18 AC 1,386 ms
72,120 KB
testcase_19 AC 1,340 ms
72,120 KB
testcase_20 AC 1,266 ms
75,592 KB
testcase_21 AC 1,051 ms
72,636 KB
testcase_22 AC 1,393 ms
76,560 KB
testcase_23 AC 1,494 ms
76,764 KB
testcase_24 AC 76 ms
32,864 KB
testcase_25 AC 802 ms
60,112 KB
testcase_26 AC 1,147 ms
70,724 KB
testcase_27 AC 989 ms
207,212 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (131 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