結果

問題 No.1007 コイン集め
ユーザー O2MTO2MT
提出日時 2021-06-09 14:00:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 95 ms / 1,500 ms
コード長 470 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 86,932 KB
実行使用メモリ 98,948 KB
最終ジャッジ日時 2023-08-18 18:33:24
合計ジャッジ時間 3,514 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
71,464 KB
testcase_01 AC 64 ms
71,444 KB
testcase_02 AC 64 ms
71,452 KB
testcase_03 AC 65 ms
71,340 KB
testcase_04 AC 63 ms
71,456 KB
testcase_05 AC 60 ms
71,528 KB
testcase_06 AC 60 ms
71,392 KB
testcase_07 AC 62 ms
71,296 KB
testcase_08 AC 62 ms
71,556 KB
testcase_09 AC 62 ms
71,364 KB
testcase_10 AC 64 ms
71,332 KB
testcase_11 AC 63 ms
71,496 KB
testcase_12 AC 93 ms
98,300 KB
testcase_13 AC 90 ms
98,272 KB
testcase_14 AC 95 ms
98,352 KB
testcase_15 AC 86 ms
95,384 KB
testcase_16 AC 86 ms
95,456 KB
testcase_17 AC 85 ms
95,468 KB
testcase_18 AC 93 ms
98,428 KB
testcase_19 AC 85 ms
91,784 KB
testcase_20 AC 93 ms
98,496 KB
testcase_21 AC 89 ms
98,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import accumulate
N,K = map(int,input().split())
N += 1
A = [0]+list(map(int,input().split()))
if A[K] == 0:
  print(0)
  exit()
if N == 2:
  print(A[-1])
  exit()
l,r = 1,N-1
for i in range(K+1,N):
  if A[i] == 0 or A[i] == 1:
    r = i
    break
for i in range(K-1,-1,-1):
  if A[i] == 1 or (i != 0 and A[i] == 0):
    l = i
    break
AC = list(accumulate(A))
if A[K] == 1:
  ans = max(AC[r]-AC[K-1],AC[K]-AC[l-1])
else:
  ans = AC[r]-AC[l-1]
print(ans)
0