結果

問題 No.1765 While Shining
ユーザー forest3forest3
提出日時 2021-11-30 02:32:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 763 bytes
コンパイル時間 1,452 ms
コンパイル使用メモリ 166,620 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-15 12:14:09
合計ジャッジ時間 3,170 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 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 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 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,380 KB
testcase_11 AC 27 ms
4,376 KB
testcase_12 AC 29 ms
4,376 KB
testcase_13 AC 26 ms
4,380 KB
testcase_14 AC 32 ms
4,376 KB
testcase_15 AC 33 ms
4,380 KB
testcase_16 AC 32 ms
4,380 KB
testcase_17 AC 32 ms
4,380 KB
testcase_18 AC 32 ms
4,380 KB
testcase_19 AC 32 ms
4,376 KB
testcase_20 AC 32 ms
4,384 KB
testcase_21 AC 32 ms
4,376 KB
testcase_22 AC 34 ms
4,380 KB
testcase_23 AC 32 ms
4,380 KB
testcase_24 AC 31 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main()
{
	int N;
	cin >> N;
	vector<int> A( N );
	for( int i = 0; i < N; i++ ) cin >> A[i];

	long long ans = 0;
	int cnt = 0;
	int f = 0;
	for( int i = 0; i < N - 1; i++ ) {
		if( f ) {
			if( f == 1 ) {
				if( A[i] == 0 ) {
					f = 0;
					cnt = 0;
				}
				else {
					f = 2;
					ans += cnt;
				}
			}
			else {
				if( A[i] ) {
					f = 0;
					cnt = 0;
					i--;
				}
				else {
					f = 1;
					ans += cnt;
					ans += 2;
					cnt++;
				}
			}
		}
		else {
			if( i + 1 < N - 1 && A[i] && A[i + 1] == 0 ) {
				cnt++;
				i++;
				f = 1;
				ans += cnt * 2;
			}
		}		
	}
	for( int i = 0; i < N - 1; i++ ) {
		if( (A[i] && A[i + 1]) || (A[i] && i + 1 == N - 1) ) ans++;
	}

	cout << ans << endl;
}

0