結果

問題 No.1007 コイン集め
ユーザー KKT89
提出日時 2020-03-08 05:38:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 14 ms / 1,500 ms
コード長 703 bytes
コンパイル時間 743 ms
コンパイル使用メモリ 75,164 KB
最終ジャッジ日時 2025-01-09 05:48:02
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,k; cin >> n >> k; k--;
	vector<ll> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	if(a[k]==0){
		cout << 0 << endl;
	}else if(a[k]==1){
		ll res=0;
		ll res2=0;
		for(int i=k-1;i>=0;i--){
			res+=a[i];
			if(a[i]<2)break;
		}
		for(int i=k+1;i<n;i++){
			res2+=a[i];
			if(a[i]<2)break;
		}
		cout << max(res,res2)+1 << endl;
	}else{
		ll res=0;
		ll res2=0;
		for(int i=k-1;i>=0;i--){
			res+=a[i];
			if(a[i]<2)break;
		}
		for(int i=k+1;i<n;i++){
			res2+=a[i];
			if(a[i]<2)break;
		}
		cout << res+res2+a[k] << endl;
	}
}
0