結果
問題 |
No.930 数列圧縮
|
ユーザー |
|
提出日時 | 2019-11-23 00:12:41 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 35 ms / 2,000 ms |
コード長 | 1,520 bytes |
コンパイル時間 | 1,062 ms |
コンパイル使用メモリ | 101,488 KB |
実行使用メモリ | 7,680 KB |
最終ジャッジ日時 | 2024-11-15 19:16:32 |
合計ジャッジ時間 | 4,154 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include <limits> #include <iostream> #include <algorithm> #include <iomanip> #include <map> #include <set> #include <queue> #include <stack> #include <numeric> #include <bitset> #include <cmath> #include <list> static const int MOD = 1000000007; using ll = long long; using namespace std; template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208; template <class T> ostream& operator<<(ostream& os, vector<T> v) { os << "{"; for (int i = 0; i < v.size(); ++i) { if(i) os << ", "; os << v[i]; } return os << "}"; } template <class L, class R> ostream& operator<<(ostream& os, pair<L, R> p) { return os << "{" << p.first << ", " << p.second << "}"; } int main() { int n; cin >> n; vector<int> v(n); for (auto &&i : v) scanf("%d", &i); if(v.front() > v.back()){ puts("No"); return 0; } vector<int> ans; list<int> l(v.begin(),v.end()); for(auto i = l.begin(); i != l.end(); ++i){ while(true){ auto j = next(i, 1); if(j != l.end() && next(j, 1) != l.end() && *i < *j && *l.begin() < *j){ ans.emplace_back(*j); l.erase(j); }else break; } } l.reverse(); if(!l.empty()){ for(auto i = ++l.begin(); i != l.end(); ++i){ ans.emplace_back(*i); } } puts("Yes"); for (int i = 0; i < n-1; ++i) { if(i) printf(" "); printf("%d", ans[i]); } puts(""); return 0; }