結果

問題 No.602 隠されていたゲーム2
ユーザー nebukuro09nebukuro09
提出日時 2017-12-08 10:36:09
言語 JavaScript
(node v21.7.1)
結果
WA  
実行時間 -
コード長 814 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 6,684 KB
実行使用メモリ 53,192 KB
最終ジャッジ日時 2024-04-21 02:02:49
合計ジャッジ時間 3,945 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
39,424 KB
testcase_01 AC 63 ms
39,168 KB
testcase_02 AC 63 ms
39,168 KB
testcase_03 AC 66 ms
39,168 KB
testcase_04 AC 63 ms
39,296 KB
testcase_05 AC 62 ms
39,424 KB
testcase_06 AC 63 ms
39,424 KB
testcase_07 AC 63 ms
39,040 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 64 ms
39,296 KB
testcase_11 AC 62 ms
39,424 KB
testcase_12 AC 67 ms
39,296 KB
testcase_13 AC 63 ms
39,424 KB
testcase_14 WA -
testcase_15 AC 63 ms
39,424 KB
testcase_16 WA -
testcase_17 AC 118 ms
46,640 KB
testcase_18 AC 203 ms
50,056 KB
testcase_19 AC 241 ms
52,804 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 145 ms
52,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

function Main(input) {
    var data = input.split("\n")
    
    var N = data[0]
    var D = data[1].split(" ")
    var X = parseInt(data[2].split(" ")[0])
    var Y = parseInt(data[2].split(" ")[1])
    var M = Math.abs(X) + Math.abs(Y)

    if (M == 0) {
        console.log(0)
        return
    }

    for (i = 0; i < N; i++) {
        D[i] = parseInt(D[i])
        if (D[i] == M) {
            console.log(1)
            return
        }
    }

    D.sort()
    var p = [-1, -1]

    for (i = 0; i < N; i++) {
        var parity = Math.abs(D[i]-M) % 2
        if (p[parity] >= 0 && Math.abs(D[i] - p[parity] <= M && M <= D[i] + p[parity])) {
            console.log(2)
            return
        }
        p[D[i]%2] = D[i]
    }

    console.log(-1)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
0