結果

問題 No.1007 コイン集め
ユーザー kappybarkappybar
提出日時 2020-03-22 20:12:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,224 bytes
コンパイル時間 1,497 ms
コンパイル使用メモリ 167,172 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-26 20:02:24
合計ジャッジ時間 3,345 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
const ll INF = 1e12;
const int MOD = 1000000007;


int main() {
        int n,k;
        cin >> n >> k;
        --k;
        vector<ll> a(n);
        rep(i,n) cin >> a[i];
        if(a[k] == 0) { cout << 0 << endl;}
        else if(a[k] == 1){
                ll res1 = 0,res2 = 0;
                for(int i = k; i >= 0;i--){
                        res1 += a[i];
                        if(a[i] == 1 && i != k) break;
                }
                for(int i = k;i < n;i++){
                        res2 += a[i];
                        if(a[i] == 1 && i != k) break;
                }
                cout << max(res1,res2) << endl;
        }
        else{
                ll res = 0;
                int l = 0,r = n-1;
                for(int i = k;i>=0;i--){
                        if(a[i] == 1) l = i;
                }
                for(int i = k;i<n;i++){
                        if(a[i] == 1) r = i;
                }
                for(int i=l;i<=r;i++){
                        res += a[i];
                }
                cout << res << endl;
        }


        return 0;
}
0