結果

問題 No.1007 コイン集め
ユーザー pitsu_kyo_propitsu_kyo_pro
提出日時 2020-03-09 11:23:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 1,500 ms
コード長 1,103 bytes
コンパイル時間 1,396 ms
コンパイル使用メモリ 163,700 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 10:18:12
合計ジャッジ時間 2,543 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
  int N,K;
  cin >> N >> K;
  K--;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  if(A[K] == 0){
    cout << 0 << endl;
    return 0;
  }
  ll sum_l=0;
  for(int i=K+1; i<N; i++){
    sum_l += A[i];
    if(A[i] < 2){
      break;
    }
  }
  ll sum_r=0;
  for(int i=K-1; i>=0; i--){
    sum_r += A[i];
    if(A[i] < 2){
      break;
    }
  }
  if(A[K] == 1){
    cout << max(sum_l,sum_r) + 1 << endl;
  }else{
    cout << sum_l + sum_r + A[K] << endl;
  }
  return 0;
}
0