結果

問題 No.930 数列圧縮
ユーザー risujirohrisujiroh
提出日時 2019-03-30 03:41:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,533 bytes
コンパイル時間 2,161 ms
コンパイル使用メモリ 170,892 KB
実行使用メモリ 5,512 KB
最終ジャッジ日時 2024-04-24 22:34:44
合計ジャッジ時間 37,062 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 6 ms
5,376 KB
testcase_05 AC 127 ms
5,376 KB
testcase_06 AC 1,803 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1,816 ms
5,376 KB
testcase_14 AC 1,816 ms
5,376 KB
testcase_15 AC 36 ms
5,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
5,376 KB
testcase_23 WA -
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1,801 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

template<class Z> Z rng(Z a, Z b) {
  static mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
  return uniform_int_distribution<Z>(a, b - 1)(mt);
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> a(n); for (auto&& e : a) cin >> e;
  using namespace chrono;
  auto start_t = steady_clock::now();
  auto solve = [&]() -> void {
    V<> l(n), r(n);
    for (int i = 0; i < n; ++i) {
      l[i] = i - 1;
      r[i] = i + 1;
    }
    V<> res;
    V<bool> used(n);
    auto chk = [&](int i) -> bool {
      if (used[i]) return false;
      if (l[i] >= 0 and a[l[i]] < a[i]) return true;
      if (r[i] < n and a[i] < a[r[i]]) return true;
      return false;
    };
    int cnt = 0;
    while (true) {
      int i = rng(0, n);
      if (chk(i)) {
        used[i] = true;
        res.push_back(a[i]);
        if (l[i] >= 0) {
          r[l[i]] = r[i];
        }
        if (r[i] < n) {
          l[r[i]] = l[i];
        }
        cnt = 0;
      }
      ++cnt;
      if (cnt > 3 * n) return;
      if (res.size() == n - 1) {
        cout << "Yes" << '\n';
        for (int i = 0; i < n - 1; ++i) {
          cout << res[i] << " \n"[i == n - 2];
        }
        exit(0);
      }
    }
  };
  while (duration_cast<milliseconds>(steady_clock::now() - start_t).count() < 1800) {
    solve();
  }
  cout << "No" << '\n';
}
0