結果

問題 No.602 隠されていたゲーム2
ユーザー titia
提出日時 2023-12-30 01:02:21
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 259 ms / 2,000 ms
コード長 634 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 21,816 KB
最終ジャッジ日時 2024-09-27 16:26:42
合計ジャッジ時間 2,889 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect,bisect_left

N=int(input())
D=sorted(map(int,input().split()))
x,y=map(int,input().split())

ODD=[]
EVEN=[]

for d in D:
    if d%2==0:
        EVEN.append(d)
    else:
        ODD.append(d)

if x==0 and y==0:
    print(0)
    exit()

Distance=abs(x)+abs(y)

if Distance in D:
    print(1)
    exit()

for d in D:
    if d<=Distance:
        L,R=Distance-d,Distance+d

    else:
        L,R=d-Distance,Distance+d

    if L%2==0:
        x0=bisect(EVEN,L-1)
        x1=bisect(EVEN,R)
    else:
        x0=bisect(ODD,L-1)
        x1=bisect(ODD,R)

    if x0!=x1:    
        print(2)
        exit()

print(-1)
0