結果

問題 No.3847 Triple Balls Removal
コンテスト
ユーザー tnakao0123
提出日時 2026-12-05 18:03:30
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 70 ms / 2,000 ms
+ 759µs
コード長 706 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 321 ms
コンパイル使用メモリ 75,392 KB
実行使用メモリ 15,868 KB
最終ジャッジ日時 2026-12-05 18:03:36
合計ジャッジ時間 4,862 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3847.cc:  No.3847 Triple Balls Removal - yukicoder
 */

#include<cstdio>
#include<stack>
#include<algorithm>
#include<utility>

using namespace std;

/* constant */

const int MAX_N = 1000000;

/* typedef */

using pii = pair<int,int>;
using stpii = stack<pii>;

/* global variables */

int as[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  stpii q;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (! q.empty() && q.top().first == as[i]) {
      if (++(q.top().second) == 3) cnt++, q.pop();
    }
    else
      q.push({as[i], 1});
  }

  printf("%d\n", cnt * 3);
  
  return 0;
}
0