結果

問題 No.1765 While Shining
ユーザー umncumnc
提出日時 2021-12-08 17:53:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,397 bytes
コンパイル時間 4,078 ms
コンパイル使用メモリ 260,996 KB
実行使用メモリ 9,084 KB
最終ジャッジ日時 2023-09-23 08:18:21
合計ジャッジ時間 6,340 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 13 ms
6,044 KB
testcase_10 AC 18 ms
7,768 KB
testcase_11 AC 16 ms
7,180 KB
testcase_12 AC 18 ms
8,024 KB
testcase_13 AC 16 ms
6,816 KB
testcase_14 AC 20 ms
7,772 KB
testcase_15 AC 20 ms
7,884 KB
testcase_16 AC 20 ms
7,912 KB
testcase_17 AC 20 ms
8,504 KB
testcase_18 AC 20 ms
8,592 KB
testcase_19 AC 19 ms
7,940 KB
testcase_20 AC 20 ms
7,772 KB
testcase_21 AC 19 ms
7,768 KB
testcase_22 AC 20 ms
9,084 KB
testcase_23 AC 20 ms
9,072 KB
testcase_24 AC 17 ms
8,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= n; ++i)
#define reps(i, s, e) for (ll i = s; i <= e; ++i)
#define rrep(i, n) for (ll i = n - 1; 0 <= i; --i)
#define all(v) v.begin(), v.end()
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = long long;
using ld = long double;
using cp = complex<ld>;
using pa = pair<ll, ll>;
using tup = tuple<ll, ll, ll>;
using vp = vector<pair<ll, ll> >;
using vtup = vector<tuple<ll, ll, ll> >;
using st = string;
using vs = vector<string>;
using vc = vector<char>;
using vvi = vector<vector<ll> >;
using vvc = vector<vector<char> >;
using vi = vector<ll>;
const ll MOD1 = 1000000007;
const ll MOD2 = 998244353;
const ll INF = (1LL << 60);

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;

  vi a(n);
  rep(i, n) cin >> a[i];

  auto b = a;
  for (int i = 1; i < n; i += 2) b[i] ^= 1;
  b.push_back(-1);
  ll pre = n;
  vi c(n);

  for (int i = n - 1; 0<= i; i--) {
    if (b[i] != b[pre]) pre = i;
    c[i] = pre + 1;
  }

  ll ans = 0;
  rep(i, n) if (a[i]) ans += min(c[i], n - 1) - i;
  cout << ans << endl;
}
0