結果

問題 No.1007 コイン集め
ユーザー pengin_2000pengin_2000
提出日時 2020-03-10 17:43:57
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 16 ms / 1,500 ms
コード長 595 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 29,312 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-27 18:45:48
合計ジャッジ時間 1,154 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<stdio.h>
int main()
{
	int n, k;
	scanf("%d %d", &n, &k);
	int i;
	long long int a[200005];
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	long long int ans[2];
	k--;
	if (a[k] == 0)
	{
		printf("0\n");
		return 0;
	}
	ans[0] = 0;
	for (i = k - 1; i >= 0; i--)
	{
		ans[0] += a[i];
		if (a[i] < 2)
			break;
	}
	ans[1] = 0;
	for (i = k + 1; i < n; i++)
	{
		ans[1] += a[i];
		if (a[i] < 2)
			break;
	}
	if (a[k] == 1)
	{
		if (ans[0] > ans[1])
			printf("%lld\n", ans[0] + 1);
		else
			printf("%lld\n", ans[1] + 1);
	}
	else
		printf("%lld\n", ans[0] + ans[1] + a[k]);
	return 0;
}
0