結果

問題 No.168 ものさし
ユーザー mbanmban
提出日時 2017-03-26 20:48:55
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 484 ms / 2,000 ms
コード長 2,192 bytes
コンパイル時間 2,926 ms
コンパイル使用メモリ 105,860 KB
実行使用メモリ 30,696 KB
最終ジャッジ日時 2023-08-25 21:04:55
合計ジャッジ時間 7,340 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
22,912 KB
testcase_01 AC 105 ms
21,756 KB
testcase_02 AC 64 ms
23,684 KB
testcase_03 AC 64 ms
21,872 KB
testcase_04 AC 64 ms
23,672 KB
testcase_05 AC 360 ms
19,800 KB
testcase_06 AC 65 ms
21,648 KB
testcase_07 AC 484 ms
19,784 KB
testcase_08 AC 332 ms
21,676 KB
testcase_09 AC 66 ms
21,816 KB
testcase_10 AC 71 ms
23,732 KB
testcase_11 AC 94 ms
22,812 KB
testcase_12 AC 168 ms
24,520 KB
testcase_13 AC 215 ms
28,972 KB
testcase_14 AC 213 ms
28,916 KB
testcase_15 AC 126 ms
23,672 KB
testcase_16 AC 115 ms
21,664 KB
testcase_17 AC 110 ms
21,724 KB
testcase_18 AC 96 ms
21,892 KB
testcase_19 AC 220 ms
30,696 KB
testcase_20 AC 226 ms
28,964 KB
testcase_21 AC 227 ms
28,864 KB
testcase_22 AC 227 ms
28,920 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.Linq;
using System.Collections;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

public class Magatro
{
    private int N;
    private long[] X, Y;
    private S[] Arr;

    private int[] Size;
    private int[] Par;

    private void Scan()
    {
        N = int.Parse(Console.ReadLine());
        X = new long[N];
        Y = new long[N];

        for (int i = 0; i < N; i++)
        {
            var line = Console.ReadLine().Split(' ');
            X[i] = int.Parse(line[0]);
            Y[i] = int.Parse(line[1]);
        }
    }

    private void Union(S s)
    {
        Union(s.A, s.B);
    }

    private void Union(int a, int b)
    {
        a = Root(a);
        b = Root(b);
        if (a == b) return;
        Par[b] = a;
        Size[a] += Size[b];
    }

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

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

    public void Solve()
    {
        Scan();
        int index = 0;
        Arr = new S[(N - 1) * N / 2];
        for (int i = 0; i < N - 1; i++)
        {
            for (int j = i + 1; j < N; j++)
            {
                var dist = (X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j]);
                Arr[index] = new S(i, j, dist);
                index++;
            }
        }

        Array.Sort(Arr, (a, b) => a.Dist.CompareTo(b.Dist));
        Size = (new int[N]).Select(i => 1).ToArray();
        Par = (new int[N]).Select((i, j) => j).ToArray();
        int ind = 0;
        for (long l = 10; true; l += 10)
        {
            long dist = l * l;
            for (int i = ind; Arr[i].Dist <= dist; i++)
            {
                ind++;
                Union(Arr[i]);
                if (Same(0, N - 1))
                {
                    Console.WriteLine(l);
                    return;
                }
            }
        }
    }
}

struct S
{
    public int A, B;
    public long Dist;
    public S(int a, int b, long dist)
    {
        A = a;
        B = b;
        Dist = dist;
    }
}
0