結果

問題 No.1007 コイン集め
ユーザー finefine
提出日時 2020-03-07 01:37:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 718 bytes
コンパイル時間 1,561 ms
コンパイル使用メモリ 164,100 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 11:41:20
合計ジャッジ時間 2,614 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 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 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 16 ms
5,376 KB
testcase_13 AC 16 ms
5,376 KB
testcase_14 AC 16 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 8 ms
5,376 KB
testcase_17 AC 8 ms
5,376 KB
testcase_18 AC 16 ms
5,376 KB
testcase_19 AC 16 ms
5,376 KB
testcase_20 AC 16 ms
5,376 KB
testcase_21 AC 16 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, K;
    cin >> n >> K;
    --K;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    if (a[K] == 0) {
        cout << 0 << "\n";
        return 0;
    }

    ll cnt_r = 1;
    for (int i = K + 1; i < n; ++i) {
        cnt_r += a[i];
        if (a[i] == 1) break;
    }

    ll cnt_l = 1;
    for (int i = K - 1; i >= 0; --i) {
        cnt_l += a[i];
        if (a[i] == 1) break;
    }

    if (a[K] == 1) {
        cout << max(cnt_l, cnt_r) << "\n";
    } else {
        cout << cnt_l + cnt_r + a[K] - 2 << "\n";
    }
    return 0;
}
0