結果

問題 No.930 数列圧縮
ユーザー Iván Soto
提出日時 2021-05-11 20:01:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 814 bytes
コンパイル時間 3,129 ms
コンパイル使用メモリ 195,268 KB
最終ジャッジ日時 2025-01-21 10:04:08
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *  author: ivanzuki   
 *  created: Tue May 11 2021
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    --a[i];
  }
  vector<int> st = {a[0]};
  vector<int> ans;
  for (int i = 1; i < n; i++) {
    while (st.size() > 1 && st.back() < a[i]) {
      ans.push_back(st.back());
      st.pop_back();
    }
    if (st.size() == 1 && st.back() < a[i]) {
      ans.push_back(a[i]);
    } else {
      st.push_back(a[i]);
    }
  }
  if (st.size() == 1) {
    assert((int) ans.size() == n - 1);
    cout << "Yes" << '\n';
    for (const auto& x : ans) {
      cout << x + 1 << ' ';
    }
    cout << '\n';
  } else {
    cout << "No" << '\n';
  }
  return 0;
}
0