結果

問題 No.1007 コイン集め
ユーザー Tsukasan_z46Tsukasan_z46
提出日時 2020-06-21 15:44:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 1,500 ms
コード長 1,106 bytes
コンパイル時間 1,902 ms
コンパイル使用メモリ 199,952 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 18:26:26
合計ジャッジ時間 3,200 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// yukicoder No.1007 コイン集め
// 2020.06.21

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K; cin >> N >> K;
  vector<ll> A(N);
  REP(i, N){
    cin >> A[i];
  }
  ll ansR = 0;
  ll ansL = 0;
  ll ans = 0;
  if(K <= N-1){
    for(int i = K; i < N; i++){
      if(A[i] < 2){
        ansR += A[i];
        break;
      }else{
        ansR += A[i];
      }
    }
  }
  if(K > 1){
    for(int i = K-2; i >= 0; i--){
      if(A[i] < 2){
        ansL += A[i]; 
        break;
      }else{
        ansL += A[i];
      }
    }
  }
  if(A[K-1] == 0){
    cout << 0 << endl;
  }else if(A[K-1] == 1){
    ans = A[K-1] + max(ansR, ansL);
    cout << ans << endl;
  }else{
    ans = A[K-1] + ansR + ansL;
    cout << ans << endl;
  }
}
0