結果

問題 No.602 隠されていたゲーム2
ユーザー daku9640daku9640
提出日時 2017-12-03 23:07:07
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 793 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 10,832 KB
実行使用メモリ 20,384 KB
最終ジャッジ日時 2023-08-22 05:40:36
合計ジャッジ時間 2,241 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,824 KB
testcase_01 AC 16 ms
7,848 KB
testcase_02 AC 16 ms
7,804 KB
testcase_03 AC 16 ms
7,960 KB
testcase_04 AC 17 ms
7,828 KB
testcase_05 AC 17 ms
7,784 KB
testcase_06 AC 17 ms
7,852 KB
testcase_07 AC 16 ms
7,788 KB
testcase_08 AC 16 ms
7,800 KB
testcase_09 AC 15 ms
7,788 KB
testcase_10 AC 16 ms
7,788 KB
testcase_11 AC 16 ms
7,868 KB
testcase_12 AC 16 ms
7,848 KB
testcase_13 AC 16 ms
7,804 KB
testcase_14 AC 16 ms
7,864 KB
testcase_15 AC 16 ms
7,884 KB
testcase_16 AC 38 ms
9,628 KB
testcase_17 AC 65 ms
11,584 KB
testcase_18 AC 71 ms
17,064 KB
testcase_19 AC 94 ms
19,356 KB
testcase_20 AC 166 ms
19,704 KB
testcase_21 AC 107 ms
20,384 KB
testcase_22 AC 84 ms
19,056 KB
testcase_23 AC 62 ms
19,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline
n = int(readline())
pq = [[], []]
for i in map(int, readline().split()):
    pq[i % 2].append(i)
x, y = map(int, readline().split())
z = abs(x) + abs(y)
def solve():
    if z == 0: return 0
    if z in pq[0] or z in pq[1]: return 1
    pq[0].sort()
    pq[1].sort()
    if z % 2 == 0:
        if pq[0]:
            if pq[0][-1] * 2 >= z:
                return 2
        if pq[1]:
            if pq[1][-1] * 2 >= z:
                return 2
    else:
        while pq[0] and pq[1]:
            t1 = pq[0][-1]
            t2 = pq[1][-1]
            if t1 + t2 >= z and max(t1, t2) - min(t1, t2) <= z:
                return 2
            if t1 > t2:
                pq[0].pop()
            else:
                pq[1].pop()
    return -1
print(solve())
0