結果

問題 No.1007 コイン集め
ユーザー ysystem7ysystem7
提出日時 2020-03-17 15:31:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 1,500 ms
コード長 1,285 bytes
コンパイル時間 2,587 ms
コンパイル使用メモリ 212,736 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-08 01:13:38
合計ジャッジ時間 4,140 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    ll n,k;
    cin>>n>>k;
    V<ll> a(n);
    cinf(n,a);
    k--;
    ll ans=0;
    ll m=k-1;
    ll cleft=0,cright=0;
    while(m>=0){
        if(a[m]==0) break;
        if(a[m]==1){
            cleft++;
            break;
        }
        cleft+=a[m];
        m--;
    }
    m=k+1;
    while(m<n){
        if(a[m]==0) break;
        if(a[m]==1){
            cright++;
            break;
        }
        cright+=a[m];
        m++;
    }
    if(a[k]==1) ans=max(cright,cleft)+1;
    else if(a[k]>=2) ans=cright+cleft+a[k];
    cout<<ans<<endl;
}
0