結果

問題 No.1007 コイン集め
ユーザー beetbeet
提出日時 2020-03-06 21:49:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 1,500 ms
コード長 769 bytes
コンパイル時間 2,031 ms
コンパイル使用メモリ 195,280 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 07:00:43
合計ジャッジ時間 3,204 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 13 ms
5,376 KB
testcase_13 AC 14 ms
5,376 KB
testcase_14 AC 15 ms
5,376 KB
testcase_15 AC 6 ms
5,376 KB
testcase_16 AC 8 ms
5,376 KB
testcase_17 AC 8 ms
5,376 KB
testcase_18 AC 15 ms
5,376 KB
testcase_19 AC 14 ms
5,376 KB
testcase_20 AC 15 ms
5,376 KB
testcase_21 AC 15 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n,k;
  cin>>n>>k;
  k--;
  vector<Int> as(n);
  for(Int i=0;i<n;i++) cin>>as[i];
  if(as[k]==0) drop(0);

  Int l=0,r=0;
  for(Int i=k-1;i>=0;i--){
    if(as[i]==0) break;
    l+=as[i];
    if(as[i]==1) break;
  }

  for(Int i=k+1;i<n;i++){
    if(as[i]==0) break;
    r+=as[i];
    if(as[i]==1) break;
  }

  if(as[k]==1) cout<<max(l,r)+1<<endl;
  else cout<<l+r+as[k]<<endl;
  return 0;
}
0