結果

問題 No.602 隠されていたゲーム2
ユーザー kuuso1kuuso1
提出日時 2017-12-02 04:13:00
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,123 bytes
コンパイル時間 949 ms
コンパイル使用メモリ 113,188 KB
実行使用メモリ 34,076 KB
最終ジャッジ日時 2024-05-06 00:54:04
合計ジャッジ時間 2,875 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
17,792 KB
testcase_01 AC 26 ms
17,792 KB
testcase_02 AC 27 ms
17,920 KB
testcase_03 WA -
testcase_04 AC 28 ms
18,048 KB
testcase_05 AC 28 ms
17,792 KB
testcase_06 AC 28 ms
17,792 KB
testcase_07 WA -
testcase_08 AC 31 ms
17,920 KB
testcase_09 AC 27 ms
17,792 KB
testcase_10 AC 29 ms
18,048 KB
testcase_11 AC 29 ms
18,048 KB
testcase_12 AC 29 ms
17,920 KB
testcase_13 AC 28 ms
17,920 KB
testcase_14 AC 29 ms
17,664 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 52 ms
20,480 KB
testcase_18 AC 81 ms
25,856 KB
testcase_19 AC 93 ms
28,032 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 95 ms
28,032 KB
testcase_23 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		
		Array.Sort(D);
		if(CheckZero()){
			Console.WriteLine(1);
			return;
		}
		if(CheckOne()){
			Console.WriteLine(1);
			return;
		}
		if(CheckTwo()){
			Console.WriteLine(2);
			return;
		}
		Console.WriteLine(-1);
		
	}
	
	bool CheckZero(){
		return X == 0 && Y == 0;
	}
	
	
	bool CheckOne(){
		for(int i=0;i<N;i++){
			if(X + Y == D[i]) return true;
		}
		return false;
	}
	
	bool CheckTwo(){
		bool ret = true;
		long[] TT = new long[]{X - Y, X + Y};
		for(int k=0;k<2;k++){
			long T = TT[k];
			bool chk = false;
			for(int i=0;i<N;i++){
				long r0 = D[i];
				if(T <= 2 * r0) {chk = true; break;}
				if(D[N-1] + r0 < T) continue;
				int l = i + 1;
				int r = N;
				if(D[l] + r0 >= T){
					if(D[l] - r0 <= T) {chk = true; break;}
					continue;
				}
				while(r - l > 1){
					int c = (r + l) / 2;
					if(D[c] + r0 < T){
						l = c;
					} else {
						r = c;
					}
				}
				if(r == N) continue;
				if(D[r] - r0 <= T) {chk = true; break;}
			}
			ret &= chk;
		}
		return ret;
	}
	
	
	
	
	
	
	
	int N;
	long[] D;
	long X,Y;
	public Sol(){
		N = ri();
		D = rla();
		var d = rla();
		X = d[0]; Y = d[1];
		if(X < 0) X *= -1;
		if(Y < 0) Y *= -1;
		if(Y > X) { Swap(ref X, ref Y);}
	}
	void Swap<T>(ref T x, ref T y){
		T tmp = x; x = y; y = tmp;
	}

	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(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
0