結果

問題 No.1007 コイン集め
コンテスト
ユーザー KKT89
提出日時 2020-03-08 05:38:56
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 7 ms / 1,500 ms
+ 44µs
コード長 703 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 458 ms
コンパイル使用メモリ 94,592 KB
実行使用メモリ 9,904 KB
最終ジャッジ日時 2026-10-13 12:12:23
合計ジャッジ時間 2,069 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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