結果

問題 No.602 隠されていたゲーム2
ユーザー vwxyz
提出日時 2022-05-16 18:41:45
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,480 ms / 2,000 ms
コード長 972 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 21,784 KB
最終ジャッジ日時 2024-09-14 11:24:48
合計ジャッジ時間 10,561 ms
ジャッジサーバーID
(参考情報)
judge1 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left,bisect_right
import sys
readline=sys.stdin.readline

N=int(readline())
D=list(map(int,readline().split()))
D0=[d for d in D if d%2==0]
D1=[d for d in D if d%2==1]
D.sort()
D0.sort()
D1.sort()
x,y=map(int,readline().split())
x,y=x+y,x-y
ans=3
if (x,y)==(0,0):
    ans=min(ans,0)
if max(abs(x),abs(y)) in D:
    ans=min(ans,1)
for d in D:
    l,r=-d,d
    for a in (-d,d):
        for xx,yy in ((x,y),(y,x)):
            if l<=xx<=r:
                m=0 if xx%2==d%2 else 1
                M=max(abs(r-xx),abs(xx-l))
            else:
                m=min(abs(r-xx),abs(xx-l))
                M=max(abs(r-xx),abs(xx-l))
            m=max(m,abs(a-yy))
            M=max(M,abs(a-yy))
            if xx%2==d%2:
                if bisect_right(D0,M)-bisect_left(D0,m):
                    ans=min(ans,2)
            else:
                if bisect_right(D1,M)-bisect_left(D1,m):
                    ans=min(ans,2)
if ans==3:
    ans=-1
print(ans)
0