結果

問題 No.602 隠されていたゲーム2
ユーザー gew1fw
提出日時 2025-06-12 19:39:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 850 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 82,424 KB
実行使用メモリ 83,148 KB
最終ジャッジ日時 2025-06-12 19:40:01
合計ジャッジ時間 2,244 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect

n = int(input())
d_list = list(map(int, input().split()))
x, y = map(int, input().split())

m = abs(x) + abs(y)

# Check if m can be achieved in one move
if m in d_list:
    print(1)
else:
    max_d = max(d_list)
    # Check if using the same distance twice can achieve m
    if 2 * max_d >= m:
        print(2)
    else:
        # Sort the list for binary search
        d_list_sorted = sorted(d_list)
        found = False
        for di in d_list_sorted:
            lower = max(m - di, di - m)
            upper = di + m
            # Find if any number in [lower, upper] exists in d_list_sorted
            left = bisect.bisect_left(d_list_sorted, lower)
            right = bisect.bisect_right(d_list_sorted, upper)
            if left < right:
                found = True
                break
        print(2 if found else -1)
0