結果
| 問題 |
No.1765 While Shining
|
| コンテスト | |
| ユーザー |
forest3
|
| 提出日時 | 2021-11-30 02:32:08 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 2,000 ms |
| コード長 | 763 bytes |
| コンパイル時間 | 1,578 ms |
| コンパイル使用メモリ | 167,816 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-02 15:37:49 |
| 合計ジャッジ時間 | 3,493 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
#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;
}
forest3