結果

問題 No.1007 コイン集め
ユーザー NagisaNagisa
提出日時 2020-03-06 22:29:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 102 ms / 1,500 ms
コード長 974 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 21,736 KB
最終ジャッジ日時 2024-04-22 08:53:55
合計ジャッジ時間 2,197 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 AC 30 ms
10,752 KB
testcase_04 AC 29 ms
10,752 KB
testcase_05 AC 29 ms
10,752 KB
testcase_06 AC 30 ms
10,752 KB
testcase_07 AC 32 ms
10,880 KB
testcase_08 AC 30 ms
10,752 KB
testcase_09 AC 29 ms
10,880 KB
testcase_10 AC 30 ms
10,752 KB
testcase_11 AC 30 ms
10,752 KB
testcase_12 AC 93 ms
21,592 KB
testcase_13 AC 94 ms
21,616 KB
testcase_14 AC 102 ms
21,720 KB
testcase_15 AC 51 ms
13,164 KB
testcase_16 AC 51 ms
13,040 KB
testcase_17 AC 50 ms
13,160 KB
testcase_18 AC 95 ms
21,608 KB
testcase_19 AC 66 ms
21,736 KB
testcase_20 AC 102 ms
21,612 KB
testcase_21 AC 80 ms
21,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int,input().split())
A = list(map(int,input().split()))
if A[K-1] == 0:
    print(0)
elif A[K-1] == 1:
    now = K-2
    l = 0
    while now >= 0:
        if A[now] >= 2:
            l += A[now]
        elif A[now] == 1:
            l += 1
            break
        else:
            break
        now -= 1
    r = 0
    now = K
    while now < N:
        if A[now] >= 2:
            r += A[now]
        elif A[now] == 1:
            r += 1
            break
        else:
            break
        now += 1
    print(max(l,r)+1)
else:
    now = K-2
    l = 0
    while now >= 0:
        if A[now] >= 2:
            l += A[now]
        elif A[now] == 1:
            l += 1
            break
        else:
            break
        now -= 1
    r = 0
    now = K
    while now < N:
        if A[now] >= 2:
            r += A[now]
        elif A[now] == 1:
            r += 1
            break
        else:
            break
        now += 1
    print(l+r+A[K-1])
0