結果
| 問題 | No.1765 While Shining | 
| コンテスト | |
| ユーザー |  penguinshunya | 
| 提出日時 | 2021-11-26 22:45:41 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 38 ms / 2,000 ms | 
| コード長 | 851 bytes | 
| コンパイル時間 | 2,076 ms | 
| コンパイル使用メモリ | 193,824 KB | 
| 最終ジャッジ日時 | 2025-01-26 01:36:32 | 
| ジャッジサーバー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];
  }
  reverse(a.begin(), a.end());
  int status = -1;
  long long 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 = i == 0 ? 0 : 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;
}
            
            
            
        