結果

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

ソースコード

diff #

import bisect

def main():
    import sys
    input = sys.stdin.read().split()
    idx = 0
    n = int(input[idx])
    idx += 1
    d = list(map(int, input[idx:idx+n]))
    idx += n
    x = int(input[idx])
    y = int(input[idx+1])
    
    D = abs(x) + abs(y)
    s = x + y
    
    if D == 0:
        print(0)
        return
    
    d_set = set(d)
    if D in d_set:
        print(1)
        return
    
    d_sorted = sorted(d)
    even_d = []
    odd_d = []
    for num in d_sorted:
        if num % 2 == 0:
            even_d.append(num)
        else:
            odd_d.append(num)
    
    possible = False
    for di in d_sorted:
        si = s - di
        required_parity = abs(si) % 2
        low = max(D - di, di - D, abs(si))
        high = di + D
        
        if low > high:
            continue
        
        if required_parity == 0:
            lst = even_d
        else:
            lst = odd_d
        
        if not lst:
            continue
        
        left = bisect.bisect_left(lst, low)
        right = bisect.bisect_right(lst, high)
        if left < right:
            possible = True
            break
    
    print(2 if possible else -1)

if __name__ == "__main__":
    main()
0