結果

問題 No.1007 コイン集め
ユーザー hiro71687khiro71687k
提出日時 2023-03-25 20:15:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 809 bytes
コンパイル時間 4,884 ms
コンパイル使用メモリ 262,292 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 05:17:42
合計ジャッジ時間 6,461 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll inf=14449999999994;
ll mod=1000000007;
int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll>a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    k--;
    ll x=0,y=0;
    for (ll i = k+1; i < n; i++)
    {
        if (a[i]<=1)
        {
            x+=a[i];
            break;
        }
        x+=a[i];
    }
    for (ll i = k-1; i >=0; i--)
    {
        if (a[i]<=1)
        {
            x+=a[i];
            break;
        }
        x+=a[i];
    }
    if (a[k]>=2)
    {
        cout << x+y+a[k] << endl;
    }else if (a[k]==1)
    {
        cout << max(x,y)+1 << endl;
    }else{
        cout << 0 << endl;
    }
}
0