結果

問題 No.3847 Triple Balls Removal
コンテスト
ユーザー Wing2C1
提出日時 2026-12-04 22:15:19
言語 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  
実行時間 208 ms / 2,000 ms
+ 486µs
コード長 599 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,292 ms
コンパイル使用メモリ 177,328 KB
実行使用メモリ 11,192 KB
最終ジャッジ日時 2026-12-04 22:15:29
合計ジャッジ時間 8,277 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> st;
    st.reserve(n);
    long long remain = 0;

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (!st.empty() && st.back().first == a) {
            st.back().second++;
            remain++;
            if (st.back().second == 3) {
                st.pop_back();
                remain -= 3;
            }
        } else {
            st.emplace_back(a, 1);
            remain++;
        }
    }

    cout << n - remain << endl;
    return 0;
}
0