結果

問題 No.1007 コイン集め
ユーザー qLethonqLethon
提出日時 2020-03-06 23:36:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 1,500 ms
コード長 617 bytes
コンパイル時間 2,372 ms
コンパイル使用メモリ 196,600 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 10:40:30
合計ジャッジ時間 3,371 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int64_t> A(n);
    copy_n(istream_iterator<int64_t>(cin), n, A.begin());
    k--;

    if (A[k] == 0){
        puts("0");
        return 0;
    }

    int64_t f = 0;
    for (int i = k - 1; i >= 0; i--){
        f += A[i];
        if (A[i] < 2)
            break;
    }

    int64_t b = 0;
    for (int i = k + 1; i < n; i++){
        b += A[i];
        if (A[i] < 2)
            break;
    }

    if (A[k] == 1){
        cout << max(f, b) + A[k] << endl;
    } else {
        cout << f + b + A[k] << endl;
    }
}
0