結果

問題 No.3847 Triple Balls Removal
コンテスト
ユーザー roastnegi
提出日時 2026-12-04 23:40:44
言語 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  
実行時間 206 ms / 2,000 ms
+ 473µs
コード長 1,183 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,639 ms
コンパイル使用メモリ 363,904 KB
実行使用メモリ 27,456 KB
最終ジャッジ日時 2026-12-04 23:40:54
合計ジャッジ時間 9,415 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge6_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using sl = set<ll>;
using pl = pair<ll, ll>;
#define MOD 998244353
#define MOD2 1000000007
#define INF 1e18
#define all(v) v.begin(), v.end()
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort(v.rbegin(), v.rend())
#define REVERSE(v) reverse(v.begin(), v.end())
#define YESNO(b) cout << ((b) ? "Yes" : "No") << endl
#define DOUT(a, b) cout << fixed << setprecision(b) << a << endl;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};


template <typename T>
void debug_out(const vector<T> &x){
    for(auto &y : x) cerr << y << " ";
    cerr << endl;
}


int main(void){
    int n;
    cin >> n;
    vl a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    stack<pl> st;
    ll rt = 0;
    for (int i = 0; i < n; i++)
    {
        if(st.empty() || st.top().first != a[i]) {
            st.push({a[i], 1});
            continue;
        }
        if(st.top().second == 2) {
            st.pop();
            rt += 3;
        } else {
            st.top().second++;
        }
    }
    cout << rt << endl;
}
0