結果
問題 | No.94 圏外です。(EASY) |
ユーザー | sekiya9311 |
提出日時 | 2017-10-05 00:49:03 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 59 ms / 5,000 ms |
コード長 | 5,047 bytes |
コンパイル時間 | 1,048 ms |
コンパイル使用メモリ | 110,976 KB |
実行使用メモリ | 20,736 KB |
最終ジャッジ日時 | 2024-06-26 08:19:09 |
合計ジャッジ時間 | 2,739 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
20,608 KB |
testcase_01 | AC | 35 ms
20,352 KB |
testcase_02 | AC | 36 ms
20,224 KB |
testcase_03 | AC | 31 ms
20,096 KB |
testcase_04 | AC | 36 ms
20,480 KB |
testcase_05 | AC | 35 ms
20,352 KB |
testcase_06 | AC | 37 ms
20,608 KB |
testcase_07 | AC | 37 ms
20,480 KB |
testcase_08 | AC | 39 ms
20,480 KB |
testcase_09 | AC | 43 ms
20,480 KB |
testcase_10 | AC | 43 ms
20,608 KB |
testcase_11 | AC | 42 ms
20,352 KB |
testcase_12 | AC | 44 ms
20,736 KB |
testcase_13 | AC | 42 ms
20,352 KB |
testcase_14 | AC | 43 ms
20,352 KB |
testcase_15 | AC | 43 ms
20,608 KB |
testcase_16 | AC | 43 ms
20,480 KB |
testcase_17 | AC | 42 ms
20,352 KB |
testcase_18 | AC | 42 ms
20,480 KB |
testcase_19 | AC | 59 ms
20,352 KB |
testcase_20 | AC | 34 ms
20,480 KB |
testcase_21 | AC | 35 ms
20,224 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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].Select(el => -1).ToArray(); } 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; } } } }