結果

問題 No.1007 コイン集め
ユーザー shoshoshoshoshosho
提出日時 2020-03-06 23:42:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,262 bytes
コンパイル時間 1,629 ms
コンパイル使用メモリ 164,488 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-22 10:45:09
合計ジャッジ時間 2,860 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  ll n,k;cin>>n>>k;
  ll a[n];rep(i,0,n)cin>>a[i];

  ll ans=0;
  bool e[2];
  e[0]=false;
  ll mi[2];CLR(mi,0);
  repr(i,k-2,0){
    if(a[i]<=1){
      if(!e[0])mi[0]=ans+a[i];
      e[0]=true;
    }
    if(a[i]==0)break;
    ans+=a[i];
  }

  e[1]=false;
  ll num=0;
  rep(i,k,n){
    if(a[i]<=1){
      if(!e[1])mi[1]=num+a[i];
      e[1]=true;
    }
    if(a[i]==0)break;
    num+=a[i];
  }

  // out(ans<<" "<<num);
  // out(mi[0]<<" "<<mi[1]);
  if(a[k-1]==0)out(0);
  else if(a[k-1]==1)out(a[k-1]+max(mi[0],mi[1]));
  else if(e[0]&&e[1])out(mi[0]+a[k-1]+mi[1]);
  else out(ans+num+a[k-1]);

  return 0;
}
0