結果
| 問題 | No.3847 Triple Balls Removal |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-12-04 21:42:41 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 54 ms / 2,000 ms |
| + 684µs | |
| コード長 | 1,449 bytes |
| 記録 | |
| コンパイル時間 | 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 |
ソースコード
#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();
}
}