結果

問題 No.921 ずんだアロー
ユーザー sash2104sash2104
提出日時 2019-11-08 22:46:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,109 bytes
コンパイル時間 823 ms
コンパイル使用メモリ 76,808 KB
実行使用メモリ 4,852 KB
最終ジャッジ日時 2023-10-13 04:23:05
合計ジャッジ時間 2,383 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 1 ms
4,372 KB
testcase_09 AC 2 ms
4,368 KB
testcase_10 AC 34 ms
4,628 KB
testcase_11 AC 36 ms
4,852 KB
testcase_12 AC 9 ms
4,368 KB
testcase_13 AC 27 ms
4,668 KB
testcase_14 AC 31 ms
4,672 KB
testcase_15 AC 18 ms
4,368 KB
testcase_16 AC 4 ms
4,368 KB
testcase_17 AC 32 ms
4,672 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 38 ms
4,840 KB
testcase_24 AC 27 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long ll;
bool done[100010];

struct Data {
  int l, r, n;
  Data(int l, int r): l(l), r(r), n(r-l+1) {}
};

// ">" のオーバーロード numを基準に大小比較を行う
bool operator < (const Data &d1, const Data &d2){
  if (d1.n == d2.n) return d1.l > d2.l;
  return d1.n < d2.n;
};

int main() {
  int n;
  cin >> n;
  int bef = -1;
  int l = 0, r = 0;
  priority_queue<Data> pq;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (a == bef) { 
      r = i;
    }
    else if (i > 0) {
      pq.push(Data(l, r));
      l = i;
      r = i;
    }
    bef = a;
  }
  pq.push(Data(l, r));

  ll ans = 0;
  while (!pq.empty()) {
    Data d = pq.top(); pq.pop();
    int add = d.n;
    if (done[d.l]) { --add; }
    else if (d.l != d.r && done[d.r]) { --add; }
    if (add == 0) continue;
    ans += add;
    if (d.l > 0) done[d.l-1] = true;
    if (d.r < n-1) done[d.r+1] = true;
    // cerr << d.l << " " << d.r << " " << d.n << " " << ans << endl;
  }
  cout << ans << endl;
}

0