結果

問題 No.94 圏外です。(EASY)
ユーザー sekiya9311sekiya9311
提出日時 2017-10-05 00:34:49
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 5,117 bytes
コンパイル時間 1,404 ms
コンパイル使用メモリ 119,536 KB
実行使用メモリ 27,064 KB
最終ジャッジ日時 2024-11-16 18:55:30
合計ジャッジ時間 3,269 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
19,968 KB
testcase_01 AC 33 ms
20,096 KB
testcase_02 AC 32 ms
20,096 KB
testcase_03 AC 29 ms
19,712 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 57 ms
20,224 KB
testcase_20 RE -
testcase_21 AC 33 ms
19,840 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;
using System.Text;
using System.Threading.Tasks;

namespace ProgrammingContest
{
    class MainClass
    {
        Scanner sc;
        static void Main(string[] args)
        {
            new MainClass().Solve();
        }

        struct Point
        {
            public double x, y;
        }

        const bool DEBUG = false;   // TODO: must check!!
        void Solve()
        {
            if (DEBUG)
            {
                string backPath = "..";
                char dirSep = System.IO.Path.DirectorySeparatorChar;
                string inFilePath = backPath + dirSep + backPath + dirSep + "in.txt";
                sc = new Scanner(new System.IO.StreamReader(inFilePath));
            }
            else
            {
                sc = new Scanner();
            }
            int n = sc.NextInt;
            Point[] p = new Point[n];
            for (int i = 0; i < n; i++)
            {
                p[i] = new Point();
                p[i].x = sc.NextDouble;
                p[i].y = sc.NextDouble;
            }
            UnionFind uf = new UnionFind(n);
            for (int i = 0; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    if (calcDist(p[i], p[j]) <= 10)
                    {
                        uf.unite(i, j);
                    }
                }
            }
            Dictionary<int, int> dic = new Dictionary<int, int>();
            int cnt = 0;
            for (int i = 0; i < n; i++)
            {
                if (!dic.ContainsKey(uf.find(i)))
                {
                    dic.Add(uf.find(i), cnt++);
                }
            }
            List<int>[] conLists = new List<int>[dic.Count].Select(el => new List<int>()).ToArray();
            for (int i = 0; i < n; i++)
            {
                conLists[uf.find(i)].Add(i);
            }
            double ma = 1;
            foreach(List<int> list in conLists)
            {
                foreach(int idx1 in list)
                {
                    foreach (int idx2 in list)
                    {
                        ma = Math.Max(ma, calcDist(p[idx1], p[idx2]) + 2);
                    }
                }
            }
            Console.WriteLine(ma);
        }
        double calcDist(Point a, Point b)
        {
            double x = a.x - b.x;
            double y = a.y - b.y;
            return Math.Sqrt(x * x + y * y);
        }
    }
    class UnionFind
    {
        private int[] uni;
        int count_;
        public UnionFind(int n)
        {
            this.uni = new int[n];
            for (int i = 0; i < n; i++)
            {
                this.uni[i] = -1;
            }
        }
        public int Count()
        {
            return this.count_;
        }
        public int Count(int n)
        {
            return -this.uni[this.find(n)];
        }
        public int find(int n)
        {
            return (this.uni[n] < 0 ? n : this.uni[n] = this.find(this.uni[n]));
        }
        public bool unite(int a, int b)
        {
            a = this.find(a);
            b = this.find(b);
            if (a == b)
            {
                return false;
            }
            if (this.uni[a] > this.uni[b])
            {
                int t = a;
                a = b;
                b = t;
            }
            this.uni[a] += this.uni[b];
            this.uni[b] = a;
            this.count_--;
            return true;
        }
        public bool same(int a, int b)
        {
            return this.find(a) == this.find(b);
        }
    }
    class Scanner
    {
        Queue<String> buffer;
        char[] sep;
        System.IO.TextReader reader;
        public Scanner(System.IO.TextReader reader = null)
        {
            this.buffer = new Queue<string>();
            this.sep = new char[] { ' ' };
            this.reader = (reader ?? Console.In);
        }
        private void CheckBuffer()
        {
            if (this.buffer.Count == 0)
            {
                String[] sreArray = this.reader.ReadLine().Split(this.sep);
                foreach (String elStr in sreArray)
                {
                    this.buffer.Enqueue(elStr);
                }
            }
        }

        public String Next
        {
            get
            {
                this.CheckBuffer();
                return this.buffer.Dequeue();
            }
        }

        public int NextInt
        {
            get
            {
                return int.Parse(this.Next);
            }
        }
        public double NextDouble
        {
            get
            {
                return double.Parse(this.Next);
            }
        }

        public long NextLong
        {
            get
            {
                return long.Parse(this.Next);
            }
        }
        public bool IsEmpty
        {
            get
            {
                this.CheckBuffer();
                return this.buffer.Count == 0;
            }
        }
    }
}
0