結果

問題 No.1007 コイン集め
ユーザー konchanksukonchanksu
提出日時 2020-04-20 21:34:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 615 bytes
コンパイル時間 548 ms
コンパイル使用メモリ 64,756 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 00:54:52
合計ジャッジ時間 2,217 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;

int n, k, i, j;

int main(){
    cin >> n >> k;
    int p, q;
    int a[n];
    int ans = 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){
            if(a[i] == 0) p = i + 1;
            if(a[i] == 1) p = i;
        }else{
            if(a[i] == 0) q = i - 1;
            if(a[i] == 1) q = i;
        }
    }
    
    for(i = p; i < q + 1; i++){
        ans += a[i];
    }
    
    cout << ans << endl;
    
    return 0;
}
0