結果
| 問題 |
No.930 数列圧縮
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-04 18:14:37 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 956 bytes |
| コンパイル時間 | 1,016 ms |
| コンパイル使用メモリ | 81,692 KB |
| 最終ジャッジ日時 | 2025-01-12 14:20:02 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 WA * 2 |
ソースコード
#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()) {
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;
}