結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 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 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>
#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;
    }
    
    if(a[k - 1] == 1) tmp = 1;
    p = 0, q = n - 1;
    for(i = 0; i < n; i++){
        if(i < k - 1){
            if(a[i] == 0) p = i + 1;
            if(a[i] == 1) p = i;
        }else if(i > k - 1){
            if(a[i] == 0) q = i - 1;
            if(a[i] == 1) q = i;
        }                }
    
    for(i = p; i < q + 1; i++){
        if(tmp == 0) ans += a[i];
        else{
            if(i < k) tmpa += a[i];
            if(i > k) tmpb += a[i];
        }
    }
    if(tmp == 1) ans = max(tmpa, tmpb);
    
    cout << ans << endl;
    
    return 0;
}
0