結果

問題 No.871 かえるのうた
ユーザー work-furukawa
提出日時 2025-04-29 21:47:07
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 721 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 82,568 KB
実行使用メモリ 105,536 KB
最終ジャッジ日時 2025-04-29 21:47:15
合計ジャッジ時間 6,916 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16 TLE * 1 -- * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import bisect
N, K = map(int,input().split())
X = list(map(int,input().split()))
A = list(map(int,input().split()))
K -= 1

imosu = [0] * N
called = [False] * N

called[K] = True
que = deque()
que.append(K)

while que:
  q = que.popleft()
  x = X[q]
  a = A[q]
  l = x - a
  r = x + a
  if l > r:
    l, r = r, l

  lidx = bisect.bisect_left(X, l)
  ridx = bisect.bisect_left(X, r+1)
  imosu[lidx] += 1
  if ridx < N:
    imosu[ridx] -= 1

  for i in range(lidx, ridx):
    if not called[i]:
      called[i] = True
      que.append(i)

accums = [0] * (N+1)
for i in range(N):
  accums[i+1] = accums[i] + imosu[i]

ans = 0
for i in range(1, N+1):
  if accums[i] > 0:
    ans += 1

print(ans)
0