結果

問題 No.94 圏外です。(EASY)
ユーザー sekiya9311sekiya9311
提出日時 2017-10-05 00:35:51
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 99 ms / 5,000 ms
コード長 5,122 bytes
コンパイル時間 2,538 ms
コンパイル使用メモリ 112,632 KB
実行使用メモリ 25,824 KB
最終ジャッジ日時 2023-09-08 15:15:04
合計ジャッジ時間 5,223 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
23,800 KB
testcase_01 AC 73 ms
21,676 KB
testcase_02 AC 75 ms
23,628 KB
testcase_03 AC 67 ms
23,416 KB
testcase_04 AC 75 ms
25,672 KB
testcase_05 AC 76 ms
23,736 KB
testcase_06 AC 76 ms
23,656 KB
testcase_07 AC 78 ms
23,584 KB
testcase_08 AC 78 ms
23,744 KB
testcase_09 AC 82 ms
25,636 KB
testcase_10 AC 83 ms
25,712 KB
testcase_11 AC 83 ms
25,672 KB
testcase_12 AC 82 ms
23,552 KB
testcase_13 AC 82 ms
23,640 KB
testcase_14 AC 82 ms
23,660 KB
testcase_15 AC 83 ms
25,824 KB
testcase_16 AC 83 ms
23,620 KB
testcase_17 AC 83 ms
21,632 KB
testcase_18 AC 82 ms
23,660 KB
testcase_19 AC 99 ms
23,672 KB
testcase_20 AC 73 ms
21,536 KB
testcase_21 AC 74 ms
23,604 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[dic[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