結果

問題 No.1007 コイン集め
ユーザー leaf_1415leaf_1415
提出日時 2020-03-06 21:54:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 15 ms / 1,500 ms
コード長 709 bytes
コンパイル時間 2,036 ms
コンパイル使用メモリ 61,616 KB
実行使用メモリ 4,464 KB
最終ジャッジ日時 2023-08-04 09:41:30
合計ジャッジ時間 3,117 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#define llint long long

using namespace std;
typedef pair<llint, llint> P;

llint n, k;
llint a[200005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	if(a[k] == 0){
		cout<< 0 << endl;
		return 0;
	}
	
	llint lsum = 0;
	for(int i = k-1; i >= 1; i--){
		if(a[i] == 0) break;
		lsum += a[i];
		if(a[i] <= 1) break;
	}
	llint rsum = 0;
	for(int i = k+1; i <= n; i++){
		if(a[i] == 0) break;
		rsum += a[i];
		if(a[i] <= 1) break;
	}
	
	if(a[k] == 1){
		cout << max(lsum, rsum) + 1 << endl;
		return 0;
	}
	
	cout << lsum + rsum + a[k] << endl;
	
	return 0;
}
0