結果

問題 No.1007 コイン集め
ユーザー takakintakakin
提出日時 2020-05-24 23:34:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 131 ms / 1,500 ms
コード長 534 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 21,856 KB
最終ジャッジ日時 2024-04-20 16:19:22
合計ジャッジ時間 2,461 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,752 KB
testcase_01 AC 32 ms
10,624 KB
testcase_02 AC 31 ms
10,624 KB
testcase_03 AC 31 ms
10,752 KB
testcase_04 AC 31 ms
10,624 KB
testcase_05 AC 30 ms
10,752 KB
testcase_06 AC 31 ms
10,624 KB
testcase_07 AC 32 ms
10,624 KB
testcase_08 AC 31 ms
10,624 KB
testcase_09 AC 31 ms
10,752 KB
testcase_10 AC 31 ms
10,624 KB
testcase_11 AC 31 ms
10,752 KB
testcase_12 AC 131 ms
21,720 KB
testcase_13 AC 129 ms
21,856 KB
testcase_14 AC 129 ms
21,724 KB
testcase_15 AC 59 ms
13,148 KB
testcase_16 AC 58 ms
13,272 KB
testcase_17 AC 60 ms
13,272 KB
testcase_18 AC 127 ms
21,560 KB
testcase_19 AC 76 ms
21,688 KB
testcase_20 AC 126 ms
21,688 KB
testcase_21 AC 105 ms
21,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
if A[k-1]==0:
  print(0)
else:
  ans=A[k-1]
  ans_l,ans_r=0,0
  l,r=1,1
  while k-1-l>=0:
    if A[k-1-l]>=2:
      ans_l+=A[k-1-l]
      l+=1
      continue
    else:
      ans_l+=A[k-1-l]
      break
  while k-1+r<n:
    if A[k-1+r]>=2:
      ans_r+=A[k-1+r]
      r+=1
      continue
    else:
      ans_r+=A[k-1+r]
      break
  if A[k-1]==1:
    print(ans+max(ans_l,ans_r))
  else:
    print(ans+ans_l+ans_r)
0