結果

問題 No.1007 コイン集め
ユーザー maspymaspy
提出日時 2020-03-06 21:49:35
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 47 ms / 1,500 ms
コード長 599 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 10,756 KB
実行使用メモリ 17,456 KB
最終ジャッジ日時 2023-08-04 09:13:19
合計ジャッジ時間 2,411 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,788 KB
testcase_01 AC 16 ms
7,852 KB
testcase_02 AC 15 ms
7,856 KB
testcase_03 AC 16 ms
7,736 KB
testcase_04 AC 16 ms
7,984 KB
testcase_05 AC 16 ms
7,772 KB
testcase_06 AC 15 ms
7,920 KB
testcase_07 AC 16 ms
7,772 KB
testcase_08 AC 16 ms
7,852 KB
testcase_09 AC 15 ms
7,736 KB
testcase_10 AC 16 ms
7,796 KB
testcase_11 AC 15 ms
7,904 KB
testcase_12 AC 46 ms
17,296 KB
testcase_13 AC 47 ms
17,240 KB
testcase_14 AC 46 ms
17,284 KB
testcase_15 AC 33 ms
10,272 KB
testcase_16 AC 33 ms
10,380 KB
testcase_17 AC 32 ms
10,180 KB
testcase_18 AC 47 ms
17,456 KB
testcase_19 AC 42 ms
17,256 KB
testcase_20 AC 47 ms
17,328 KB
testcase_21 AC 47 ms
17,416 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