結果

問題 No.3847 Triple Balls Removal
コンテスト
ユーザー 👑 ssmbc2929_bartok
提出日時 2026-12-04 21:48:37
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 52 ms / 2,000 ms
+ 260µs
コード長 1,043 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,545 ms
コンパイル使用メモリ 383,364 KB
実行使用メモリ 9,900 KB
最終ジャッジ日時 2026-12-04 21:48:46
合計ジャッジ時間 8,649 ms
ジャッジサーバーID
(参考情報)
judge6_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define rrep(i, a, b) for (ll i = a; i >= b; --i)
#ifndef LOCAL
#define cerr \
  if (false) cerr
#endif

// --- 初期設定(入出力の高速化と小数15桁出力) ---
struct Init {
  Init() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
  }
} init;
// ------------------------------------------------

int main() {
  int n;
  cin >> n;
  stack<int> st;
  ll ans = 0;

  rep(i, 0, n) {
    int inp;
    cin >> inp;
    st.push(inp);
    while (st.size() >= 3) {
      int t1 = st.top();
      st.pop();
      int t2 = st.top();
      st.pop();
      int t3 = st.top();
      st.pop();
      if (t1 != t2 || t2 != t3 || t3 != t1) {
        st.push(t3);
        st.push(t2);
        st.push(t1);
        break;
      }
      ans += 3;
    }
  }
  cout << ans << "\n";
  return 0;
}

// Pre-written library: https://github.com/ssmbc2929bartok/cp-env
0