結果

問題 No.1007 コイン集め
ユーザー st-IO-OIst-IO-OI
提出日時 2020-03-06 22:37:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 103 ms / 1,500 ms
コード長 632 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 21,768 KB
最終ジャッジ日時 2024-04-22 09:42:52
合計ジャッジ時間 2,290 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,752 KB
testcase_01 AC 33 ms
10,752 KB
testcase_02 AC 32 ms
10,752 KB
testcase_03 AC 31 ms
10,752 KB
testcase_04 AC 30 ms
10,752 KB
testcase_05 AC 30 ms
10,752 KB
testcase_06 AC 31 ms
10,752 KB
testcase_07 AC 30 ms
10,752 KB
testcase_08 AC 30 ms
10,752 KB
testcase_09 AC 36 ms
10,880 KB
testcase_10 AC 30 ms
10,752 KB
testcase_11 AC 30 ms
10,880 KB
testcase_12 AC 97 ms
21,688 KB
testcase_13 AC 98 ms
21,560 KB
testcase_14 AC 95 ms
21,680 KB
testcase_15 AC 58 ms
13,136 KB
testcase_16 AC 59 ms
13,004 KB
testcase_17 AC 58 ms
13,128 KB
testcase_18 AC 100 ms
21,572 KB
testcase_19 AC 74 ms
21,768 KB
testcase_20 AC 103 ms
21,704 KB
testcase_21 AC 90 ms
21,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(int, input().split())
a = [int(x) for x in input().split()]

if a[k-1] == 0:
    ans = 0
else:
    for i in range(min([k,n-1]), n):
        if a[i] == 1:
            k1 = i
            break
        elif a[i] == 0:
            k1 = i-1
            break
        if i == n-1:
            k1 = n-1
    for i in range(max([k-2, 0]), -1, -1):
        if a[i] == 1:
            k2 = i
            break
        elif a[i] == 0:
            k2 = i+1
            break
        if i == 0:
            k2 = 0
    if a[k-1] != 1:
        ans = sum(a[k2:k1+1])
    else:
        ans = max([sum(a[k2:k]), sum(a[k-1:k1+1])])
print(ans)
0