結果

問題 No.602 隠されていたゲーム2
ユーザー daku9640
提出日時 2017-12-03 00:21:18
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 799 ms / 2,000 ms
コード長 981 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 21,736 KB
最終ジャッジ日時 2024-12-16 00:03:08
合計ジャッジ時間 4,976 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import combinations
readline = sys.stdin.readline
n = int(readline())
d = sorted(map(int, readline().split()))
x, y = map(int, readline().split())
l = abs(x) + abs(y)
ans = -1
if l == 0:
    ans = 0
elif l in d:
    ans = 1
elif l%2==0:
    if max(d)*2 >= l:
        ans = 2
else:
    d1 = [x for x in d if x%2==0]
    d2 = [x for x in d if x%2==1]
    if d1 != []:
        for a in d2:
            low = 0; high = len(d1)-1
            while low < high:
                mid = (high+low) >> 1
                if(a+d1[mid]>=l): high = mid
                else: low = mid+1
            if(a+d1[low]<l): continue
            b = low
            low = 0; high = len(d1)-1
            while low < high:
                mid = (high+low+1) >> 1
                if(a>d1[mid] or abs(a-d1[mid])<=l): low = mid
                else: high = mid-1
            if(abs(a-d1[low])>l): continue
            c = low
            if(b<=c):
                ans = 2
print(ans)
0