結果

問題 No.1007 コイン集め
ユーザー mikianaaamikianaaa
提出日時 2020-08-31 10:51:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,175 bytes
コンパイル時間 1,563 ms
コンパイル使用メモリ 169,524 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 15:10:49
合計ジャッジ時間 2,797 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, K;
    cin >> N >> K;
    K--;
    vector<ll> A(N);
    rep(i, N) { cin >> A[i]; }

    bool judge = (A[K] >= 3 ? 1 : 0);

    // right
    ll right = K, rtmp = 0;
    while (right < N) {
        if (A[right] >= 2)
            rtmp += A[right];
        else if (A[right] == 1) {
            rtmp += A[right];
            break;
        } else
            break;
        right++;
    }

    // left
    ll left = K, ltmp = 0;
    while (left > 0) {
        if (A[left] >= 2)
            ltmp += A[left];
        else if (A[left] == 1) {
            ltmp += A[left];
            break;
        } else
            break;
        left--;
    }

    if (judge && rtmp > 0 && ltmp > 0) {
        cout << rtmp + ltmp - A[K] << endl;
    } else if (judge) {
        cout << rtmp + ltmp << endl;
    } else
        cout << max(rtmp, ltmp) << endl;
}
0