結果

問題 No.1765 While Shining
ユーザー penguinshunya
提出日時 2021-11-26 22:38:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 832 bytes
コンパイル時間 2,041 ms
コンパイル使用メモリ 193,840 KB
最終ジャッジ日時 2025-01-26 01:33:04
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19 WA * 3
権限があれば一括ダウンロードができます

ソースコード

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];
  }
  reverse(a.begin(), a.end());
  int status = -1;
  int ans = 0;
  int acc = 0;
  for (int i = 0; i < n; i++) {
    if (status == -1) {
      if (a[i] == 1) {
        status = 0;
        acc = i == 0 ? 0 : 1;
        ans += acc;
      } else {
        status = 1;
        acc = 1;
      }
    } else if (status == 0) {
      if (a[i] == 0) {
        status = 1;
        acc += 1;
      } else {
        status = 0;
        acc = 1;
        ans += acc;
      }
    } else if (status == 1) {
      if (a[i] == 1) {
        status = 0;
        acc += 1;
        ans += acc;
      } else {
        status = 1;
        acc = 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
0