結果

問題 No.602 隠されていたゲーム2
ユーザー nebukuro09nebukuro09
提出日時 2017-12-02 01:47:04
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,914 bytes
コンパイル時間 2,182 ms
コンパイル使用メモリ 103,788 KB
実行使用メモリ 44,096 KB
最終ジャッジ日時 2023-08-18 18:53:35
合計ジャッジ時間 4,859 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
21,436 KB
testcase_01 AC 55 ms
21,668 KB
testcase_02 AC 55 ms
21,660 KB
testcase_03 AC 56 ms
21,600 KB
testcase_04 AC 56 ms
23,632 KB
testcase_05 AC 56 ms
21,564 KB
testcase_06 AC 55 ms
21,640 KB
testcase_07 WA -
testcase_08 AC 57 ms
23,564 KB
testcase_09 WA -
testcase_10 AC 54 ms
23,648 KB
testcase_11 AC 57 ms
23,616 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 55 ms
21,556 KB
testcase_16 AC 69 ms
22,788 KB
testcase_17 AC 80 ms
25,284 KB
testcase_18 AC 111 ms
34,188 KB
testcase_19 AC 126 ms
33,952 KB
testcase_20 AC 126 ms
34,544 KB
testcase_21 AC 116 ms
33,512 KB
testcase_22 WA -
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 = 0; i < N; ++i) {   
            int hi = i;
            int lo = 0;
            while (hi - lo > 1) {
                int mid = (hi + lo) / 2;
                if (D[i] - D[mid] >= M) {
                    lo = mid;
                } else {
                    hi = mid;
                }
            }

            if (lo == i) {
                lo -= 1;
            }

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

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

            if (hi == i) {
                hi += 1;
            }

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

        Console.WriteLine(-1);
    }
}
0