結果

問題 No.94 圏外です。(EASY)
ユーザー mbanmban
提出日時 2017-04-11 15:01:28
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 89 ms / 5,000 ms
コード長 2,249 bytes
コンパイル時間 2,521 ms
コンパイル使用メモリ 107,476 KB
実行使用メモリ 26,636 KB
最終ジャッジ日時 2023-09-08 15:06:36
合計ジャッジ時間 5,117 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
24,440 KB
testcase_01 AC 66 ms
26,472 KB
testcase_02 AC 66 ms
26,440 KB
testcase_03 AC 56 ms
22,444 KB
testcase_04 AC 66 ms
26,448 KB
testcase_05 AC 68 ms
26,352 KB
testcase_06 AC 68 ms
26,608 KB
testcase_07 AC 69 ms
24,360 KB
testcase_08 AC 73 ms
26,532 KB
testcase_09 AC 80 ms
26,504 KB
testcase_10 AC 78 ms
24,424 KB
testcase_11 AC 78 ms
24,452 KB
testcase_12 AC 76 ms
24,512 KB
testcase_13 AC 75 ms
24,472 KB
testcase_14 AC 76 ms
24,536 KB
testcase_15 AC 76 ms
22,436 KB
testcase_16 AC 76 ms
26,604 KB
testcase_17 AC 75 ms
24,472 KB
testcase_18 AC 77 ms
26,432 KB
testcase_19 AC 89 ms
24,472 KB
testcase_20 AC 70 ms
24,480 KB
testcase_21 AC 68 ms
26,636 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        new Magatro().Solve();
    }
}

public class Magatro
{
    private int N;
    P[] XY;
    int[] Par;
    List<int>[] List;

    private void Scan()
    {
        N = int.Parse(Console.ReadLine());
        XY = new P[N];
        for (int i = 0; i < N; i++)
        {
            string[] s = Console.ReadLine().Split(' ');
            XY[i] = new P(int.Parse(s[0]), int.Parse(s[1]));
        }
    }

    private void Union(int a, int b)
    {
        a = Root(a);
        b = Root(b);
        if (a == b) return;
        Par[b] = a;
        foreach (int i in List[b])
        {
            List[a].Add(i);
        }
    }

    private int Root(int a)
    {
        return Par[a] == a ? a : Root(Par[a]);
    }

    private bool Same(int a, int b)
    {
        return Root(a) == Root(b);
    }

    public void Solve()
    {
        Scan();
        if( N == 0)
        {
            Console.WriteLine(1);
            return;
        }
        Par = new int[N];
        List = new List<int>[N];
        for (int i = 0; i < N; i++)
        {
            Par[i] = i;
            List[i] = new List<int>();
            List[i].Add(i);
        }

        for (int i = 0; i < N - 1; i++)
        {
            for (int j = i + 1; j < N; j++)
            {
                if (Dist(XY[i], XY[j]) <= 10 * 10)
                {
                    Union(i, j);
                }
            }
        }

        var hs = new HashSet<int>();
        int ans = 0;
        for (int i = 0; i < N; i++)
        {
            int j = Root(i);
            if (!hs.Add(j)) continue ;
            for (int k = 0; k < List[j].Count - 1; k++)
            {
                for (int l = k + 1; l < List[j].Count; l++)
                {
                    ans = Math.Max(Dist(XY[List[j][k]], XY[List[j][l]]), ans);
                }
            }
        }

        Console.WriteLine(Math.Sqrt(ans) + 2);
    }

    public int Dist(P a, P b)
    {
        return (a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y);
    }
}

public struct P
{
    public int X, Y;
    public P(int x, int y)
    {
        X = x;
        Y = y;
    }
}
0