結果

問題 No.168 ものさし
ユーザー kuuso1kuuso1
提出日時 2015-03-20 00:49:43
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 718 ms / 2,000 ms
コード長 3,116 bytes
コンパイル時間 3,807 ms
コンパイル使用メモリ 106,128 KB
実行使用メモリ 61,288 KB
最終ジャッジ日時 2023-08-25 20:47:09
合計ジャッジ時間 10,170 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 193 ms
30,116 KB
testcase_01 AC 61 ms
20,768 KB
testcase_02 AC 59 ms
20,700 KB
testcase_03 AC 59 ms
20,732 KB
testcase_04 AC 59 ms
20,640 KB
testcase_05 AC 57 ms
18,708 KB
testcase_06 AC 60 ms
22,812 KB
testcase_07 AC 61 ms
22,680 KB
testcase_08 AC 60 ms
20,812 KB
testcase_09 AC 65 ms
22,804 KB
testcase_10 AC 73 ms
20,772 KB
testcase_11 AC 173 ms
31,952 KB
testcase_12 AC 413 ms
44,136 KB
testcase_13 AC 654 ms
61,204 KB
testcase_14 AC 447 ms
27,892 KB
testcase_15 AC 60 ms
20,756 KB
testcase_16 AC 64 ms
20,812 KB
testcase_17 AC 69 ms
22,804 KB
testcase_18 AC 83 ms
20,756 KB
testcase_19 AC 558 ms
46,064 KB
testcase_20 AC 530 ms
42,300 KB
testcase_21 AC 718 ms
61,288 KB
testcase_22 AC 604 ms
46,448 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;
using System.Collections.Generic;
 
class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long[,] Dist=new long[N,N];
		for(int i=0;i<N;i++){
			for(int j=i+1;j<N;j++){
				long l=0;
				long r=(long)2e9;
				long c=(l+r)/2;
				while(r-l>1){
					c=(l+r)/2;
					if(c*c>d2(P[i],P[j])){
						r=c;
					}else{
						l=c;
					}
				}
				while(c*c>d2(P[i],P[j]))c--;
				while(c*c<d2(P[i],P[j]))c++;
				if(c%10!=0)c+=10-c%10;
				Dist[i,j]=Dist[j,i]=c;
			}
		}
		
		long Max=0;
		bool[] used=new bool[N];
		used[0]=true;
		SkewHeap<Pair2> SH=new SkewHeap<Pair2>();
		for(int i=1;i<N;i++){
			SH.Push(new Pair2(i,Dist[0,i]));
		}
		
		while(SH.Count>0){
			var p=SH.Top;SH.Pop();
			if(used[p.Pos])continue;
			
			Max=Math.Max(Max,p.Cost);
			used[p.Pos]=true;
			if(p.Pos==N-1)break;
			for(int i=0;i<N;i++){
				if(!used[i]){
					SH.Push(new Pair2(i,Dist[p.Pos,i]));
				}
			}
		}
		Console.WriteLine(Max);
		
		
		
		
		
	}
	int N;
	Pair[] P;
	public Sol(){
		N=ri();
		P=new Pair[N];
		for(int i=0;i<N;i++){
			var d=rla();
			P[i]=new Pair(d[0],d[1]);
		}
	}

	class Pair{
		public long X,Y;
		public Pair(long x,long y){
			X=x;Y=y;
		}
	}
	long d2(Pair p,Pair q){
		return (p.X-q.X)*(p.X-q.X)+(p.Y-q.Y)*(p.Y-q.Y);
	}
	
	
	
	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}

class Pair2 : IComparable<Pair2> {
	public int Pos;
	public long Cost;
	public Pair2(int p, long c) {
		Pos = p; Cost = c;
	}
	public int CompareTo(Pair2 t) {
		//return this.Cost > t.Cost ? -1 : this.Cost < t.Cost ? 1 : 0;
		return this.Cost > t.Cost ? 1 : this.Cost < t.Cost ? -1 : 0;
	}
}


class SkewHeap<T> where T:IComparable<T>{
	public int Count{
		get{return cnt;}
		private set{cnt=value;}
	}
	
	public SkewHeap(){
		root=null;
		this.Count=0;
	}
	
	public void Push(T v){
		NodeSH<T> p=new NodeSH<T>(v);
		root=NodeSH<T>.Meld(root,p);
		this.Count++;
	}
	
	public void Pop(){
		if(root==null)return;
		root=NodeSH<T>.Meld(root.L,root.R);
		this.Count--;
	}
	
	public T Top{
		get{return root.Val;}
	}
	
	int cnt;
	NodeSH<T> root;
	
	class NodeSH<S> where S : IComparable<S> {
		public NodeSH<S> L, R;
		public S Val;

		public NodeSH(S v){
			Val = v;
			L = null; R = null;
		}
		public static NodeSH<S> Meld(NodeSH<S> a, NodeSH<S> b){
			if(a == null)return b;
			if (b == null) return a;
			if (a.Val.CompareTo(b.Val) > 0) swap(ref a, ref b);
			a.R = Meld(a.R, b);
			swap(ref a.L, ref a.R);
			return a;
		}

		static void swap<U>(ref U x, ref U y) {
			U t = x; x = y; y = t;
		}
	}
}
0