結果

問題 No.3847 Triple Balls Removal
コンテスト
ユーザー dayo ZOI
提出日時 2026-12-04 21:42:41
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 54 ms / 2,000 ms
+ 684µs
コード長 1,449 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,914 ms
コンパイル使用メモリ 359,840 KB
実行使用メモリ 19,944 KB
最終ジャッジ日時 2026-12-04 21:42:54
合計ジャッジ時間 6,586 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge6_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <csetjmp>
using namespace std;
using ll = long long;
using ld = long double;
using pll = array<ll, 2>;
using vl = vector<ll>;
template <class T> using vec = vector<T>;
template <class T> using vv = vec<vec<T>>;
template <class T> using vvv = vv<vec<T>>;
template <class T> using minpq = priority_queue<T, vector<T>, greater<T>>;
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define reps(i, l, r) for (ll i = (l); i < (r); ++i)
#define rrep(i, l, r) for (ll i = (r) - 1; i >= (l); --i)
#define sz(x) (ll)(x).size()
template <typename T> bool chmax(T &a, const T &b) {
  return a < b ? a = b, true : false;
}
template <typename T> bool chmin(T &a, const T &b) {
  return a > b ? a = b, true : false;
}

const ll INF = 1LL << 60;

using ull = unsigned long long;
using ulll = __uint128_t;

void solve() {
  ll n;
  cin >> n;
  stack<pll> st; // col, cnt
  st.push({-1, 1});
  rep(i, n) {
    ll a;
    cin >> a;
    if(st.top()[0] == a) st.top()[1]++;
    else st.push({a, 1});
    if(st.top()[1] % 3 == 0) st.pop();
  }
  ll ans = -1;
  while(!st.empty()) {
    auto [color, cnt] = st.top();
    st.pop();
    ans += cnt;
    // cout << " " << color << " " << cnt << endl;
  }
  cout << n - ans << endl;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
}
0