結果
問題 | No.930 数列圧縮 |
ユーザー |
|
提出日時 | 2020-08-04 18:18:27 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 148 ms / 2,000 ms |
コード長 | 1,067 bytes |
コンパイル時間 | 1,404 ms |
コンパイル使用メモリ | 81,596 KB |
最終ジャッジ日時 | 2025-01-12 14:21:28 |
ジャッジサーバーID (参考情報) |
judge1 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include <iostream> #include <vector> #include <set> void solve() { int n; std::cin >> n; std::set<int> rem; for (int i = 1; i <= n; ++i) rem.insert(i); std::vector<int> ans; std::vector<int> stk; while (n--) { int x; std::cin >> x; rem.erase(x); if (stk.empty() || x < stk.back()) { stk.push_back(x); } else if (rem.lower_bound(stk.front()) == rem.end()) { if (x < stk.front()) { std::cout << "No\n"; return; } while (!stk.empty()) { ans.push_back(stk.back()); stk.pop_back(); } stk.push_back(x); } else { ans.push_back(x); } } if (stk.size() != 1) { std::cout << "No\n"; } else { std::cout << "Yes\n"; for (auto a : ans) std::cout << a << " "; std::cout << "\n"; } } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }