結果
問題 | No.930 数列圧縮 |
ユーザー |
![]() |
提出日時 | 2019-11-22 22:59:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 20 ms / 2,000 ms |
コード長 | 934 bytes |
コンパイル時間 | 1,682 ms |
コンパイル使用メモリ | 174,124 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-11 04:35:08 |
合計ジャッジ時間 | 3,680 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); int n; cin>>n; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } vector<int> ans; int now = a[0]; stack<int> st; st.push(a[0]); for(int i=1;i<n;i++){ if(now < a[i]){ while(now != a[0]){ if(st.top() > a[i]) break; ans.push_back(now); now = st.top(); st.pop(); if(now == a[0]) st.push(a[0]); } ans.push_back(a[i]); } else{ st.push(now); now = a[i]; } } if(ans.size()==n-1){ cout << "Yes\n"; for(auto i:ans){ cout << i << " "; } cout << "\n"; return 0; } cout << "No\n"; }