結果

問題 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
コンパイル時間 79 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 21,544 KB
最終ジャッジ日時 2024-04-22 08:51:17
合計ジャッジ時間 1,890 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,496 KB
testcase_01 AC 26 ms
10,496 KB
testcase_02 AC 25 ms
10,496 KB
testcase_03 AC 26 ms
10,624 KB
testcase_04 AC 26 ms
10,624 KB
testcase_05 AC 30 ms
10,752 KB
testcase_06 AC 26 ms
10,496 KB
testcase_07 AC 25 ms
10,624 KB
testcase_08 AC 24 ms
10,624 KB
testcase_09 AC 25 ms
10,496 KB
testcase_10 AC 25 ms
10,496 KB
testcase_11 AC 27 ms
10,624 KB
testcase_12 AC 79 ms
21,524 KB
testcase_13 AC 84 ms
21,528 KB
testcase_14 AC 81 ms
21,272 KB
testcase_15 AC 45 ms
12,884 KB
testcase_16 AC 44 ms
12,752 KB
testcase_17 AC 45 ms
12,756 KB
testcase_18 AC 80 ms
21,420 KB
testcase_19 AC 85 ms
21,540 KB
testcase_20 AC 83 ms
21,544 KB
testcase_21 AC 70 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