結果
| 問題 | 
                            No.1007 コイン集め
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Tsukasan_z46
                         | 
                    
| 提出日時 | 2020-06-21 15:36:15 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,019 bytes | 
| コンパイル時間 | 1,778 ms | 
| コンパイル使用メモリ | 195,036 KB | 
| 最終ジャッジ日時 | 2025-01-11 08:59:23 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 WA * 3 | 
ソースコード
#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{
    ans = A[K-1] + ansR + ansL;
    cout << ans << endl;
  }
}
            
            
            
        
            
Tsukasan_z46