結果

問題 No.1007 コイン集め
ユーザー Y17Y17
提出日時 2020-03-06 22:37:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 42 ms / 1,500 ms
コード長 778 bytes
コンパイル時間 1,648 ms
コンパイル使用メモリ 146,912 KB
実行使用メモリ 5,116 KB
最終ジャッジ日時 2023-08-04 12:08:41
合計ジャッジ時間 3,114 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 37 ms
4,928 KB
testcase_13 AC 38 ms
5,116 KB
testcase_14 AC 39 ms
5,068 KB
testcase_15 AC 16 ms
4,380 KB
testcase_16 AC 16 ms
4,380 KB
testcase_17 AC 16 ms
4,380 KB
testcase_18 AC 40 ms
4,840 KB
testcase_19 AC 42 ms
4,792 KB
testcase_20 AC 42 ms
4,780 KB
testcase_21 AC 40 ms
4,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long

int n, k;
int a[100010];

signed main(){
	cin >> n >> k;

	for(int i = 0;i < n;i++){
		cin >> a[i];
	}
	k--;

	vector<int> lv, rv;
	int ans = 0;

	for(int i = 0;i < k;i++){
		if(a[i] <= 1) lv.clear();
		if(a[i] > 0) lv.push_back(a[i]);
	}

	int left = 0;
	int right = 0;
	int noko = 0;
	if(lv.size() > 0){
		for(int i = 0;i < lv.size();i++){
			left += lv[i];
		}
	}

	for(int i = n-1;i > k;i--){
		if(a[i] <= 1) rv.clear();
		if(a[i] > 0) rv.push_back(a[i]);
	}

	if(rv.size() > 0){
		for(int i = 0;i < rv.size();i++){
			right += rv[i];
		}
	}

	if(a[k] == 0){
		cout << 0 << endl;
	}else if(a[k] == 1){
		cout << max(left, right)+1 << endl;
	}else{
		cout << left + right + a[k] << endl;
	}

	return 0;
}
0