結果

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

ソースコード

diff #
raw source code

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

int main(){
    // 入出力の高速化
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N;
    cin >> N;
    
    int ans = 0;

    stack<int> s;
    s.push(-1);
    s.push(-1);
    for(int i=0; i<N; i++){
        int c;
        cin >> c;
        s.push(c);

        int top1 = s.top(); s.pop();
        int top2 = s.top(); s.pop();
        int top3 = s.top(); s.pop();

        if(top1 == top2 && top2 == top3){
            ans += 3;
        }
        else{
            s.push(top3);
            s.push(top2);
            s.push(top1);
        }
    }

    cout << ans << "\n";

    return 0;

}
0