結果

問題 No.1765 While Shining
ユーザー V_MelvilleV_Melville
提出日時 2021-12-02 13:50:52
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 494 bytes
コンパイル時間 3,418 ms
コンパイル使用メモリ 243,620 KB
実行使用メモリ 4,744 KB
最終ジャッジ日時 2023-09-18 10:14:29
合計ジャッジ時間 5,099 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 21 ms
4,376 KB
testcase_10 AC 30 ms
4,396 KB
testcase_11 AC 26 ms
4,376 KB
testcase_12 AC 29 ms
4,376 KB
testcase_13 AC 25 ms
4,380 KB
testcase_14 AC 32 ms
4,744 KB
testcase_15 AC 32 ms
4,712 KB
testcase_16 AC 32 ms
4,560 KB
testcase_17 AC 32 ms
4,596 KB
testcase_18 AC 32 ms
4,556 KB
testcase_19 AC 33 ms
4,660 KB
testcase_20 AC 33 ms
4,500 KB
testcase_21 AC 32 ms
4,496 KB
testcase_22 AC 32 ms
4,588 KB
testcase_23 AC 32 ms
4,580 KB
testcase_24 AC 31 ms
4,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::vector;
using ll = long long;

int main() {
	int n;
	cin >> n;
	
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	
	vector<int> dp(n);
	for (int i = n-2; i >= 0; --i) {
		if (a[i] == 0) dp[i] = 0;
		else if (a[i+1] == 1) dp[i] = 1;
		else {
			if (i == n-2) dp[i] = 1;
			else dp[i] = dp[i+2] + 2;
		}
	}
	
	ll ans = 0;
	rep(i, n) ans += dp[i];
	cout << ans << '\n';
	
	return 0;
}
0