結果

問題 No.1007 コイン集め
ユーザー onsen_manjuuuonsen_manjuuu
提出日時 2020-06-14 19:04:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 630 bytes
コンパイル時間 1,617 ms
コンパイル使用メモリ 166,772 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-09 23:55:46
合計ジャッジ時間 3,680 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
using ll = long long;


int main()
{
    ll n, k; cin >> n >> k;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++)cin >> a[i];
    k--;
    if(!a[k]) {
        cout << 0 << endl;
        return 0;
    }

    ll sr = 0, sl = 0;
    ll ind = k+1;
    while(ind < n - 1 && a[ind] >= 2) {
        sr += a[ind];
        ind++;
    }
    sr += a[ind];
    ind = k-1;

    while(ind > 0 && a[ind] >= 2) {
        sl += a[ind];
        ind--;
    }
    sl += a[ind];

    if(a[k] == 1) {
        cout << max(sr, sl) + 1 << endl;
    } else {
        cout << sr + sl + a[k] << endl;
    }


}
0