結果

問題 No.1007 コイン集め
ユーザー yuboolkuyuboolku
提出日時 2020-03-06 23:09:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 1,500 ms
コード長 1,171 bytes
コンパイル時間 1,408 ms
コンパイル使用メモリ 164,316 KB
実行使用メモリ 4,448 KB
最終ジャッジ日時 2023-08-04 12:47:44
合計ジャッジ時間 2,779 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>

#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;

int main(){

    int N, K;
    cin >> N >> K;
    int l = 0;
    int r = N-1;
    ll A[N];
    rep(i, N) {
        cin >> A[i];
        if (A[i] <= 1 && i < K - 1) {
            l = i;
        } else if (A[i] <= 1 && i > K - 1 && r == N-1) {
            r = i;
        }
    }

    ll ans1 = 0;
    ll ans2 = 0;
    REP(i, l, K) {
        ans1 += A[i];
    }

    REP(i, K, r+1) {
        ans2 += A[i];
    }

//    cout << ans1 << " " << ans2 << endl;

    if (A[K - 1] == 0) {
        cout << 0 << endl;
    } else if (A[K - 1] == 1) {
        cout << max(ans1 , ans2+1) << endl;
    } else {
        cout << ans1 + ans2 << endl;
    }

}
0