結果
問題 | No.930 数列圧縮 |
ユーザー |
![]() |
提出日時 | 2019-11-22 23:02:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 107 ms / 2,000 ms |
コード長 | 1,136 bytes |
コンパイル時間 | 1,860 ms |
コンパイル使用メモリ | 176,532 KB |
実行使用メモリ | 10,800 KB |
最終ジャッジ日時 | 2024-10-11 04:38:00 |
合計ジャッジ時間 | 4,828 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define int long long#define REP(i,n) for(int i = 0;i < (int)(n);i++)#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)#define FOR(i,s,n) for(int i = s;i < (int)n;i++)#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)#define ALL(a) a.begin(),a.end()#define IN(a, x, b) (a<=x && x<b)template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}constexpr long long INF = 1e18;signed main(){int N;cin>>N;vector<int>a(N);int l = -1,r = -1;REP(i,N){cin>>a[i];a[i]--;}if(a[0]==N-1||a[N-1]==0||a[0]>a[N-1]){cout<<"No"<<endl;return 0;}vector<int>ans;vector<int>tmp;int ma = N - 1;set<int>st;REP(i,N)st.insert(i);FOR(i,1,N){if(a[i] == *prev(st.end())){while(tmp.size()){int t = tmp.back();st.erase(t);tmp.pop_back();ans.push_back(t);}st.erase(a[i]);ans.push_back(a[i]);}else{tmp.push_back(a[i]);}}cout<<"Yes"<<endl;REP(i,ans.size())cout << ans[i] + 1 << " \n"[i+1 == ans.size()];}