結果

問題 No.1007 コイン集め
ユーザー betrue12
提出日時 2020-03-06 21:57:50
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 52 ms / 1,500 ms
コード長 596 bytes
コンパイル時間 2,261 ms
コンパイル使用メモリ 194,784 KB
最終ジャッジ日時 2025-01-09 05:05:17
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    K--;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    int64_t L = 0, R = 0;
    int pt = K-1;
    while(pt > 0 && A[pt] >= 2) pt--;
    if(pt >= 0) for(int i=pt; i<K; i++) L += A[i];
    pt = K+1;
    while(pt < N-1 && A[pt] >= 2) pt++;
    if(pt < N) for(int i=K+1; i<=pt; i++) R += A[i];
    int64_t ans = 0;
    if(A[K] == 0){
        ans = 0;
    }else if(A[K] == 1){
        ans = max(L, R) + 1;
    }else{
        ans = L+R+A[K];
    }
    cout << ans << endl;
    return 0;
}
0