結果

問題 No.930 数列圧縮
ユーザー kazumakazuma
提出日時 2019-11-22 21:57:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 595 bytes
コンパイル時間 1,934 ms
コンパイル使用メモリ 196,040 KB
最終ジャッジ日時 2025-01-08 04:58:42
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	if (a.front() > a.back()) {
		cout << "No" << endl;
		return 0;
	}
	vector<int> st, res;
	for (int i = 1; i < N; i++) {
		if (a[i] > a[0]) {
			while (!st.empty()) {
				res.push_back(st.back());
				st.pop_back();
			}
			res.push_back(a[i]);
		}
		else {
			st.push_back(a[i]);
		}
	}
	cout << "Yes" << endl;
	for (int i = 0; i < N - 1; i++) {
		cout << res[i] << " \n"[i + 1 == N - 1];
	}
	return 0;
}
0