結果

問題 No.1765 While Shining
ユーザー bonKotsubonKotsu
提出日時 2022-07-24 14:57:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,129 bytes
コンパイル時間 4,162 ms
コンパイル使用メモリ 259,836 KB
実行使用メモリ 4,732 KB
最終ジャッジ日時 2023-09-20 14:13:53
合計ジャッジ時間 6,199 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 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,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 21 ms
4,380 KB
testcase_10 AC 30 ms
4,404 KB
testcase_11 AC 26 ms
4,472 KB
testcase_12 AC 29 ms
4,396 KB
testcase_13 AC 26 ms
4,376 KB
testcase_14 AC 33 ms
4,620 KB
testcase_15 AC 32 ms
4,568 KB
testcase_16 AC 32 ms
4,592 KB
testcase_17 AC 33 ms
4,700 KB
testcase_18 AC 32 ms
4,608 KB
testcase_19 AC 33 ms
4,668 KB
testcase_20 AC 32 ms
4,568 KB
testcase_21 AC 32 ms
4,604 KB
testcase_22 AC 32 ms
4,568 KB
testcase_23 AC 32 ms
4,732 KB
testcase_24 AC 32 ms
4,568 KB
権限があれば一括ダウンロードができます

ソースコード

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