結果

問題 No.1007 コイン集め
ユーザー CleyLCleyL
提出日時 2020-03-06 22:16:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 1,500 ms
コード長 1,937 bytes
コンパイル時間 942 ms
コンパイル使用メモリ 96,372 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 08:23:40
合計ジャッジ時間 1,972 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 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 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 15 ms
5,376 KB
testcase_13 AC 15 ms
5,376 KB
testcase_14 AC 16 ms
5,376 KB
testcase_15 AC 9 ms
5,376 KB
testcase_16 AC 8 ms
5,376 KB
testcase_17 AC 9 ms
5,376 KB
testcase_18 AC 16 ms
5,376 KB
testcase_19 AC 16 ms
5,376 KB
testcase_20 AC 16 ms
5,376 KB
testcase_21 AC 16 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
  int n,k;cin>>n>>k;k--;
  vector<long long> A(n);
  for(int i = 0; n > i; i++){
    cin>>A[i];
  }
  if(!A[k]){
    cout << 0 << endl;
    return 0;
  }
  long long ans = 0;
  for(int i = k+1; n > i; i++){
    ans += A[i];
    if(A[i] <= 1){
      break;
    }
  }
  long long ans2 = 0;
  for(int i = k-1; 0 <= i; i--){
    ans2 += A[i];
    if(A[i] <= 1){
      break;
    }
  }
  if(A[k] == 1){
    cout << max(ans,ans2)+1 << endl;
  }else{
    cout << ans+ans2+A[k] << endl;
  }
}
0