結果

問題 No.1007 コイン集め
ユーザー maspymaspy
提出日時 2020-03-06 21:49:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 72 ms / 1,500 ms
コード長 599 bytes
コンパイル時間 126 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 20,140 KB
最終ジャッジ日時 2024-04-22 06:59:43
合計ジャッジ時間 2,031 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,624 KB
testcase_01 AC 30 ms
10,624 KB
testcase_02 AC 31 ms
10,624 KB
testcase_03 AC 31 ms
10,752 KB
testcase_04 AC 30 ms
10,752 KB
testcase_05 AC 31 ms
10,624 KB
testcase_06 AC 30 ms
10,624 KB
testcase_07 AC 30 ms
10,752 KB
testcase_08 AC 31 ms
10,752 KB
testcase_09 AC 31 ms
10,624 KB
testcase_10 AC 30 ms
10,624 KB
testcase_11 AC 31 ms
10,752 KB
testcase_12 AC 70 ms
20,140 KB
testcase_13 AC 69 ms
20,012 KB
testcase_14 AC 71 ms
20,044 KB
testcase_15 AC 52 ms
13,040 KB
testcase_16 AC 52 ms
13,044 KB
testcase_17 AC 53 ms
12,912 KB
testcase_18 AC 72 ms
20,016 KB
testcase_19 AC 64 ms
20,056 KB
testcase_20 AC 70 ms
20,016 KB
testcase_21 AC 70 ms
20,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


# %%
N, K = map(int, readline().split())
A = [0] + list(map(int, read().split())) + [0]


# %%
def solve_right(A):
    Z = A.index(0)
    A = A[:Z + 1]
    if 1 not in A:
        return sum(A)
    i = A.index(1)
    return sum(A[:i]) + 1


def solve(A, K):
    if A[K] == 0:
        return 0
    R = solve_right(A[K + 1:])
    L = solve_right(A[:K][::-1])
    if A[K] == 1:
        return 1 + max(L, R)
    return A[K] + L + R


# %%
print(solve(A, K))
0