結果

問題 No.1007 コイン集め
ユーザー konchanksukonchanksu
提出日時 2020-04-20 22:11:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 872 bytes
コンパイル時間 588 ms
コンパイル使用メモリ 67,676 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 00:56:18
合計ジャッジ時間 1,848 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

int n, k, i, j;

int main(){
    cin >> n >> k;
    int p, q;
    int a[n];
    int ans = 0;
    int tmp = 0, tmpa = 0, tmpb = 0;
    for(i = 0; i < n; i++){cin >> a[i];}
    
    if(a[k - 1] == 0){ 
        cout << 0 << endl;
        return 0;
    }
    
    p = 0, q = n - 1;
    for(i = 0; i < n; i++){
        if(i < k - 1 && (a[i] == 1 || a[i] == 0)){
            p = i;
        }else if(i > k - 1 && (a[i] == 1 || a[i] == 0)){
            q = i;
            break;
        }
    }
    
    if(a[k - 1] == 1){
        for(i = p; i <= q; i++){
            if(i < k - 1) tmpa += a[i];
            if(i > k - 1) tmpb += a[i];
        }
        ans = max(tmpa, tmpb) + 1;
    }else{
        for(i = p; i <= q; i++){
            ans += a[i];
        }
    }
    
    cout << ans << endl;
    
    return 0;
}
0