結果

問題 No.1007 コイン集め
ユーザー ptotqptotq
提出日時 2020-03-06 22:26:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 85 ms / 1,500 ms
コード長 446 bytes
コンパイル時間 108 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 21,668 KB
最終ジャッジ日時 2024-10-14 08:04:42
合計ジャッジ時間 1,974 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 27 ms
10,624 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 AC 28 ms
10,624 KB
testcase_04 AC 28 ms
10,624 KB
testcase_05 AC 31 ms
10,624 KB
testcase_06 AC 31 ms
10,624 KB
testcase_07 AC 27 ms
10,752 KB
testcase_08 AC 29 ms
10,752 KB
testcase_09 AC 28 ms
10,752 KB
testcase_10 AC 28 ms
10,624 KB
testcase_11 AC 27 ms
10,752 KB
testcase_12 AC 84 ms
21,396 KB
testcase_13 AC 83 ms
21,404 KB
testcase_14 AC 85 ms
21,528 KB
testcase_15 AC 48 ms
12,876 KB
testcase_16 AC 49 ms
12,756 KB
testcase_17 AC 48 ms
12,752 KB
testcase_18 AC 84 ms
21,668 KB
testcase_19 AC 82 ms
21,668 KB
testcase_20 AC 84 ms
21,544 KB
testcase_21 AC 72 ms
21,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N, K = map(int, input().split())
a = list(map(int, input().split()))
left, right = 0, 0
for i in range(K, N):
    if a[i] < 2:
        right += a[i] == 1
        break
    right += a[i]

for i in range(K-2, -1, -1):
    if a[i] < 2:
        left += a[i] == 1
        break
    left += a[i]

if a[K-1] == 0:
    print(0)
elif a[K-1] == 1:
    print(max(left, right)+1)
else:
    print(left + right + a[K-1])
0