結果

問題 No.1007 コイン集め
ユーザー tempura_pptempura_pp
提出日時 2020-03-06 21:42:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 1,500 ms
コード長 945 bytes
コンパイル時間 1,014 ms
コンパイル使用メモリ 119,372 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 05:37:28
合計ジャッジ時間 1,929 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	
	int n, k;
	cin>>n>>k;
	--k;
	vector<int> a(n);
	rep(i,n)cin>>a[i];
	if(a[k]==0){
		cout<<0<<endl;
		return 0;
	}
	int j = k+1;
	ll sj = 0;
	while(j<n && a[j]>=2){
		sj += a[j];
		j++;
	}
	if(j<n && a[j]==1)++sj;

	int i = k-1;
	ll si = 0;
	while(i>=0 && a[i]>=2)si += a[i--];
	if(i>=0 && a[i]==1)++si;
	if(a[k]==1){
		cout<<max(si,sj)+1<<endl;
	}
	else cout<<si+sj+a[k]<<endl;
	return 0;
}
0