結果
問題 | No.930 数列圧縮 |
ユーザー |
![]() |
提出日時 | 2019-12-12 23:19:33 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 43 ms / 2,000 ms |
コード長 | 1,273 bytes |
コンパイル時間 | 672 ms |
コンパイル使用メモリ | 67,332 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 22:06:01 |
合計ジャッジ時間 | 3,526 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
//隣り合うもの操作系は、木で見る方法があるけど、今回は区間と区間をマージする×N-1回と考えるのが簡単そう。//a___b -- c___d -- e___f//全然分からない。俺は雰囲気でコードを書いている。//…a[0] > a[n-1]ならダメは証明できた。逆はOKっぽいけど、未証明。#include <iostream>#include <stack>#include <vector>#define rep(i, n) for(i = 0; i < n; i++)using namespace std;typedef pair<int, int> P;int n;int a[100000];stack<P> stk;int main() {int i;cin >> n;rep(i, n) cin >> a[i];vector<int> ans;stk.push(P(a[0], a[0]));for (i = 1; i < n; i++) {stk.push(P(a[i], a[i]));while (stk.size() >= 2) {P r = stk.top(); stk.pop();P l = stk.top(); stk.pop();if (l.first < r.second) {if (l.first != l.second) ans.push_back(l.second);if (r.first != r.second) ans.push_back(r.first);stk.push(P(l.first, r.second));}else {stk.push(l);stk.push(r);break;}}}if (stk.size() >= 2) {cout << "No" << endl;return 0;}P last = stk.top();ans.push_back(last.second);cout << "Yes" << endl;rep(i, ans.size()) {cout << ans[i];if (i + 1 < ans.size()) cout << " ";}cout << endl;return 0;}