結果

問題 No.94 圏外です。(EASY)
ユーザー AreTrashAreTrash
提出日時 2016-09-23 09:26:17
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 91 ms / 5,000 ms
コード長 3,467 bytes
コンパイル時間 2,546 ms
コンパイル使用メモリ 112,216 KB
実行使用メモリ 25,852 KB
最終ジャッジ日時 2023-09-08 14:59:37
合計ジャッジ時間 5,079 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
23,652 KB
testcase_01 AC 67 ms
23,696 KB
testcase_02 AC 68 ms
25,792 KB
testcase_03 AC 69 ms
23,712 KB
testcase_04 AC 70 ms
21,784 KB
testcase_05 AC 71 ms
23,712 KB
testcase_06 AC 72 ms
23,800 KB
testcase_07 AC 75 ms
23,712 KB
testcase_08 AC 80 ms
21,680 KB
testcase_09 AC 89 ms
25,808 KB
testcase_10 AC 88 ms
23,792 KB
testcase_11 AC 86 ms
23,780 KB
testcase_12 AC 89 ms
23,800 KB
testcase_13 AC 87 ms
25,852 KB
testcase_14 AC 86 ms
23,892 KB
testcase_15 AC 86 ms
23,832 KB
testcase_16 AC 87 ms
23,776 KB
testcase_17 AC 86 ms
25,836 KB
testcase_18 AC 85 ms
21,688 KB
testcase_19 AC 91 ms
25,768 KB
testcase_20 AC 67 ms
25,768 KB
testcase_21 AC 67 ms
23,684 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;

namespace No94{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var N = sr.Next<int>();
            var R = sr.Next<int>(N, 2).Select(a => new{X = a[0], Y = a[1]}).ToArray();

            Func<int, int, int, int, double> dist = (x1, y1, x2, y2) => Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
            var uf = new UnionFind(N);

            for(var i = 0; i < N; i++){
                for(var j = i + 1; j < N; j++){
                    if(dist(R[i].X, R[i].Y, R[j].X, R[j].Y) <= 10.0) uf.Unite(i, j);
                }
            }

            var res = 1.0 + Math.Sign(N);
            for(var i = 0; i < N; i++){
                for(var j = i + 1; j < N; j++){
                    if(uf.IsSameSet(i, j)) res = Math.Max(res, 2.0 + dist(R[i].X, R[i].Y, R[j].X, R[j].Y));
                }
            }

            Console.WriteLine(res);
            //---------------------------------
        }
    }

    public class Ex{
        public static void Swap<T>(ref T left, ref T right){
            var tmp = left;
            left = right;
            right = tmp;
        }
    }

    public class UnionFind{
        private readonly int[] _rank;
        private readonly int[] _p;

        public UnionFind(int size){
            _rank = new int[size];
            _p = new int[size];

            for(var i = 0; i < size; i++){
                _rank[i] = 0;
                _p[i] = i;
            }
        }

        public void Unite(int x, int y){
            x = FindSet(x);
            y = FindSet(y);

            if(_rank[x] > _rank[y]) _p[y] = x;
            if(_rank[x] < _rank[y]) _p[x] = y;
            if(_rank[x] == _rank[y]){
                _p[x] = y;
                _rank[y]++;
            }
        }

        public bool IsSameSet(int x, int y){
            return FindSet(x) == FindSet(y);
        }

        public int FindSet(int x){
            if(_p[x] == x) return x;
            return _p[x] = FindSet(_p[x]);
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];
        private readonly System.IO.StreamReader _sr = new System.IO.StreamReader(Console.OpenStandardInput());

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = _sr.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var ret = new T[x];
            for(var i = 0; i < x; ++i) ret[i] = Next<T>();
            return ret;
        }

        public T[][] Next<T>(int y, int x){
            var ret = new T[y][];
            for(var i = 0; i < y; ++i) ret[i] = Next<T>(x);
            return ret;
        }
    }
}
0