結果

問題 No.1765 While Shining
ユーザー bonKotsu
提出日時 2022-07-24 14:57:22
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 1,129 bytes
コンパイル時間 5,046 ms
コンパイル使用メモリ 250,776 KB
最終ジャッジ日時 2025-01-30 13:39:50
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define LP pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
template<class T>
void chmax(T& a, T b) { a = max(a, b); };
template<class T>
void chmin(T& a, T b) { a = min(a, b); };

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> s(n);
  int l = 0, r = 0;
  while (l < n-1) {
    if (a[l] == 0) {
      l++;
      r++;
      continue;
    }
    int cnt = 0;
    // rをすすめる
    while (r < n) {
      cnt++;
      r++;
      if (r == n-1 || a[r-1]+a[r] != 1) break;
    }
    // l をすすめる
    bool flag = true;
    while (l < r) {
      if (flag) {
        s[l] = cnt;
        flag = false;
        cnt -= 2;
      } else {
        s[l] = 0;
        flag = true; 
      }
      l++;
    }
  }
  ll ans = 0;
  rep(i,n) ans += s[i];
  cout << ans << endl;
  return 0;
}
0