結果

問題 No.1007 コイン集め
ユーザー kohei2019kohei2019
提出日時 2022-07-11 23:39:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 100 ms / 1,500 ms
コード長 1,042 bytes
コンパイル時間 392 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 91,552 KB
最終ジャッジ日時 2023-09-04 21:40:22
合計ジャッジ時間 3,572 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,104 KB
testcase_01 AC 74 ms
70,840 KB
testcase_02 AC 74 ms
71,364 KB
testcase_03 AC 74 ms
71,144 KB
testcase_04 AC 73 ms
71,356 KB
testcase_05 AC 74 ms
71,244 KB
testcase_06 AC 74 ms
71,120 KB
testcase_07 AC 73 ms
70,956 KB
testcase_08 AC 73 ms
71,016 KB
testcase_09 AC 72 ms
71,112 KB
testcase_10 AC 74 ms
71,148 KB
testcase_11 AC 72 ms
71,068 KB
testcase_12 AC 100 ms
91,364 KB
testcase_13 AC 98 ms
91,024 KB
testcase_14 AC 100 ms
90,996 KB
testcase_15 AC 90 ms
88,128 KB
testcase_16 AC 91 ms
88,224 KB
testcase_17 AC 91 ms
88,260 KB
testcase_18 AC 98 ms
91,304 KB
testcase_19 AC 96 ms
90,892 KB
testcase_20 AC 98 ms
91,552 KB
testcase_21 AC 98 ms
91,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K = map(int,input().split())
lsA = list(map(int,input().split()))
K -= 1
if lsA[K] == 0:
    print(0)
elif lsA[K] == 1:
    a1 = 0
    ind = K+1
    while ind < N:
        if lsA[ind] == 0:
            break
        elif lsA[ind] == 1:
            a1 += 1
            break
        else:
            a1 += lsA[ind]
            ind += 1
    a2 = 0
    ind = K-1
    while 0 <= ind:
        if lsA[ind] == 0:
            break
        elif lsA[ind] == 1:
            a2 += 1
            break
        else:
            a2 += lsA[ind]
            ind -= 1
    print(max(a1,a2)+1)
else:
    a1 = 0
    ind = K+1
    while ind < N:
        if lsA[ind] == 0:
            break
        elif lsA[ind] == 1:
            a1 += 1
            break
        else:
            a1 += lsA[ind]
            ind += 1
    a2 = 0
    ind = K-1
    while 0 <= ind:
        if lsA[ind] == 0:
            break
        elif lsA[ind] == 1:
            a2 += 1
            break
        else:
            a2 += lsA[ind]
            ind -= 1
    print(a1+a2+lsA[K]) 
0