結果
問題 | No.168 ものさし |
ユーザー |
![]() |
提出日時 | 2016-09-26 05:15:19 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 970 ms / 2,000 ms |
コード長 | 3,720 bytes |
コンパイル時間 | 1,229 ms |
コンパイル使用メモリ | 109,696 KB |
実行使用メモリ | 20,096 KB |
最終ジャッジ日時 | 2024-12-24 07:15:27 |
合計ジャッジ時間 | 7,716 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;using System.Linq;namespace No168{public class Program{public static void Main(string[] args){var sr = new StreamReader();//---------------------------------var N = sr.Next<int>();var P = sr.Next<long>(N, 2).Select(a => new{X = a[0], Y = a[1]}).ToArray();Func<long, long, long, long, long> squareDist = (x1, y1, x2, y2) => (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);Func<int, int> check = x =>{var uf = new UnionFind(N);for(var i = 0; i < N; i++){for(var j = i + 1; j < N; j++){if(squareDist(P[i].X, P[i].Y, P[j].X, P[j].Y) <= 100L * x * x) uf.Unite(i, j);}}return uf.IsSameSet(0, N - 1) ? 2 : 0;};Console.WriteLine(~Ex.BinarySearch(check, 1, 0, 150000000) * 10);//---------------------------------}}public class Ex{//発見した場合は f(ret) == key//発見できなかった場合は f(ret - 1) < ~key < f(ret)public static int BinarySearch(Func<int, int> f, int key, int left, int right){while(left != right){var mid = (left + right) / 2;if(f(mid) == key) return mid;if(f(mid) > key) right = mid;if(f(mid) < key) left = mid + 1;}return ~left;}}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;}}}