結果

問題 No.1007 コイン集め
ユーザー maspy
提出日時 2020-03-06 21:49:35
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 69 ms / 1,500 ms
コード長 599 bytes
コンパイル時間 196 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 20,144 KB
最終ジャッジ日時 2024-10-14 06:13:21
合計ジャッジ時間 2,155 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

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