結果

問題 No.602 隠されていたゲーム2
ユーザー nebukuro09nebukuro09
提出日時 2017-12-02 01:58:50
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,480 bytes
コンパイル時間 2,094 ms
コンパイル使用メモリ 100,924 KB
実行使用メモリ 37,408 KB
最終ジャッジ日時 2023-08-18 18:58:13
合計ジャッジ時間 4,764 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
21,696 KB
testcase_01 AC 51 ms
21,608 KB
testcase_02 AC 53 ms
19,464 KB
testcase_03 AC 53 ms
19,472 KB
testcase_04 AC 54 ms
21,492 KB
testcase_05 AC 53 ms
19,660 KB
testcase_06 AC 54 ms
21,492 KB
testcase_07 WA -
testcase_08 AC 53 ms
21,712 KB
testcase_09 WA -
testcase_10 AC 53 ms
23,692 KB
testcase_11 AC 54 ms
21,596 KB
testcase_12 AC 54 ms
21,652 KB
testcase_13 AC 57 ms
23,496 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 83 ms
25,252 KB
testcase_18 AC 110 ms
36,264 KB
testcase_19 AC 117 ms
35,964 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
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.Linq;

public class Program
{
    static void Main()
    {
        string s = Console.ReadLine();
        int N = int.Parse(s);

        s = Console.ReadLine();
        var t = s.Split(' ');
        var D = new long[N];
        for (int i = 0; i < N; ++i) {
            D[i] = long.Parse(t[i]);
        }
        Array.Sort(D);

        s = Console.ReadLine();
        t = s.Split(' ');

        long x = long.Parse(t[0]);
        long y = long.Parse(t[1]);

        long X = Math.Abs(x + y);
        long Y = Math.Abs(x - y);
        long M = Math.Max(X, Y);

        if (x == 0 && y == 0) {
            Console.WriteLine(-1);
            return;
        }

        if (D.Contains(M)) {
            Console.WriteLine(1);
            return;
        } 

        for (int i = 1; i < N; ++i) {   
            if (D[i] - D[i-1] <= M && M <= D[i] + D[i-1]) {
                Console.WriteLine(2);
                return;
            }
        }

        for (int i = 0; i < N-1; ++i) {   
            int hi = N;
            int lo = i+1;
            while (hi - lo > 1) {
                int mid = (hi + lo) / 2;
                if (D[mid] - D[i] <= M) {
                    lo = mid;
                } else {
                    hi = mid;
                }
            }

            if (D[hi] - D[i] <= M && M <= D[i] + D[hi]) {
                Console.WriteLine(2);
                return;
            }
        }

        Console.WriteLine(-1);
    }
}
0