結果

問題 No.1007 コイン集め
ユーザー rlangevinrlangevin
提出日時 2023-01-19 20:04:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 101 ms / 1,500 ms
コード長 447 bytes
コンパイル時間 498 ms
コンパイル使用メモリ 87,204 KB
実行使用メモリ 91,796 KB
最終ジャッジ日時 2023-09-04 10:49:45
合計ジャッジ時間 4,291 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,216 KB
testcase_01 AC 73 ms
71,428 KB
testcase_02 AC 72 ms
71,408 KB
testcase_03 AC 73 ms
71,540 KB
testcase_04 AC 74 ms
71,328 KB
testcase_05 AC 73 ms
71,052 KB
testcase_06 AC 73 ms
71,568 KB
testcase_07 AC 73 ms
71,544 KB
testcase_08 AC 73 ms
71,328 KB
testcase_09 AC 73 ms
71,240 KB
testcase_10 AC 72 ms
71,540 KB
testcase_11 AC 74 ms
71,096 KB
testcase_12 AC 100 ms
91,512 KB
testcase_13 AC 100 ms
91,576 KB
testcase_14 AC 99 ms
91,448 KB
testcase_15 AC 89 ms
88,584 KB
testcase_16 AC 91 ms
88,492 KB
testcase_17 AC 92 ms
88,352 KB
testcase_18 AC 100 ms
91,608 KB
testcase_19 AC 101 ms
91,724 KB
testcase_20 AC 99 ms
91,796 KB
testcase_21 AC 99 ms
91,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int, input().split())
A = list(map(int, input().split()))
left, right = 0, N
K -= 1
for i in range(K - 1, -1, -1):
    if A[i] <= 1:
        left = i
        break
for i in range(K + 1, N):
    if A[i] <= 1:
        right = i + 1
        break
L, R = 0, 0
for i in range(left, K):
    L += A[i]
for i in range(K + 1, right):
    R += A[i]
if A[K] == 0:
    print(0)
elif A[K] == 1:
    print(max(L, R) + 1)
else:
    print(L + R + A[K])
0