結果

問題 No.871 かえるのうた
ユーザー stng
提出日時 2022-07-23 17:03:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,502 ms / 2,000 ms
コード長 704 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 82,420 KB
実行使用メモリ 92,568 KB
最終ジャッジ日時 2024-11-30 11:10:05
合計ジャッジ時間 7,452 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import bisect

n,k = map(int,input().split())
x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

ans = [0]*(n)

d = deque()
d.append(k-1)
l = k-1
r = k-1
ans[k-1] = 1

while len(d):
    tmp = d.popleft()
    pos = x[tmp]
    nl = bisect.bisect_left(x,pos-a[tmp])
    nr = bisect.bisect_right(x,pos+a[tmp])
    #print(nl,nr)
    #exit()
    for i in range(nl,l):
        #print(i,"ll")
        if ans[i] == 1:
            break
        d.append(i)
        ans[i] = 1
    for i in range(r,nr):
        #print(i,"rr")
        if ans[i] == 1:
            continue
        d.append(i)
        ans[i] = 1
    #exit()
    l = nl
    r = nr
print(sum(ans))
0