結果

問題 No.1007 コイン集め
ユーザー hedwig100hedwig100
提出日時 2020-04-06 14:06:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 57 ms / 1,500 ms
コード長 1,413 bytes
コンパイル時間 107 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 19,116 KB
最終ジャッジ日時 2023-09-20 10:32:53
合計ジャッジ時間 2,206 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,948 KB
testcase_01 AC 16 ms
7,856 KB
testcase_02 AC 16 ms
7,888 KB
testcase_03 AC 16 ms
8,372 KB
testcase_04 AC 16 ms
8,204 KB
testcase_05 AC 16 ms
8,240 KB
testcase_06 AC 16 ms
7,772 KB
testcase_07 AC 16 ms
7,760 KB
testcase_08 AC 16 ms
7,788 KB
testcase_09 AC 15 ms
7,852 KB
testcase_10 AC 16 ms
7,900 KB
testcase_11 AC 16 ms
7,948 KB
testcase_12 AC 56 ms
18,928 KB
testcase_13 AC 53 ms
19,116 KB
testcase_14 AC 57 ms
19,060 KB
testcase_15 AC 34 ms
10,700 KB
testcase_16 AC 34 ms
10,588 KB
testcase_17 AC 34 ms
10,728 KB
testcase_18 AC 57 ms
19,040 KB
testcase_19 AC 49 ms
19,112 KB
testcase_20 AC 57 ms
19,064 KB
testcase_21 AC 52 ms
19,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    k -= 1

    if a[k] == 0:
        print(0)
        return 
    
    if a[k] == 1:
        tmp1 = 0
        for i in range(k + 1,n):
            if a[i] > 1:
                tmp1 += a[i]
            elif a[i] == 1:
                tmp1 += 1
                break
            else:
                break
        
        tmp2 = 0
        for i in range(k - 1,-1,-1):
            if a[i] > 1:
                tmp2 += a[i]
            elif a[i] == 1:
                tmp2 += 1
                break
            else:
                break
        
        ans = max(tmp1,tmp2) + 1
        print(ans)
        return
    
    if a[k] > 1:
        tmp1 = 0
        for i in range(k + 1,n):
            if a[i] > 1:
                tmp1 += a[i]
            elif a[i] == 1:
                tmp1 += 1
                break
            else:
                break
        
        tmp2 = 0
        for i in range(k - 1,-1,-1):
            if a[i] > 1:
                tmp2 += a[i]
            elif a[i] == 1:
                tmp2 += 1
                break
            else:
                break
        
        ans = tmp1 + tmp2 + a[k]
        print(ans)
        return
            
if __name__ =='__main__':
    main()  
0