結果

問題 No.930 数列圧縮
ユーザー leaf_1415leaf_1415
提出日時 2019-11-22 22:34:22
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,375 bytes
コンパイル時間 566 ms
コンパイル使用メモリ 67,608 KB
実行使用メモリ 7,000 KB
最終ジャッジ日時 2024-04-19 12:03:18
合計ジャッジ時間 3,357 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 6 ms
6,940 KB
testcase_14 AC 7 ms
6,940 KB
testcase_15 AC 16 ms
6,940 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 19 ms
7,000 KB
testcase_24 AC 1 ms
6,940 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <queue>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#define llint long long

using namespace std;

llint n;
llint a[100005];
bool used[100005];
vector<llint> lvec, rvec, ans;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	lvec.push_back(1);
	for(int i = 1; i < n; i++){
		if(a[i] > a[i+1]){
			lvec.push_back(i+1);
			rvec.push_back(i);
		}
	}
	rvec.push_back(n);
	
	bool flag = true, valid = false;
	for(int i = 0; i < lvec.size(); i++){
		if(a[n] < a[lvec[i]]) flag = false;
	}
	if(flag){
		for(int i = 0; i < lvec.size(); i++){
			if(lvec[i] < n) ans.push_back(a[lvec[i]]), used[lvec[i]] = true;
		}
		for(int i = 1; i < n; i++){
			if(!used[i]) ans.push_back(a[i]);
		}
		valid = true;
	}
	
	flag = true;
	for(int i = 0; i < rvec.size(); i++){
		if(a[1] > a[rvec[i]]) flag = false;
	}
	reverse(rvec.begin(), rvec.end());
	if(flag && !valid){
		for(int i = 0; i < rvec.size(); i++){
			if(rvec[i] > 1) ans.push_back(a[rvec[i]]), used[rvec[i]] = true;
		}
		for(int i = n; i > 1; i--){
			if(!used[i]) ans.push_back(a[i]);
		}
		valid = true;
	}
	
	if(valid){
		cout << "Yes" << endl;
		reverse(ans.begin(), ans.end());
		for(int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
		cout << endl;
	}
	else cout << "No" << endl;
	
	return 0;
}
0