結果

問題 No.1051 PQ Permutation
ユーザー 沙耶花沙耶花
提出日時 2020-05-08 22:10:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,452 bytes
コンパイル時間 2,956 ms
コンパイル使用メモリ 206,548 KB
実行使用メモリ 7,588 KB
最終ジャッジ日時 2023-09-19 07:39:01
合計ジャッジ時間 8,817 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 2 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 356 ms
7,424 KB
testcase_16 AC 343 ms
7,352 KB
testcase_17 WA -
testcase_18 AC 91 ms
6,576 KB
testcase_19 AC 92 ms
6,500 KB
testcase_20 AC 251 ms
7,016 KB
testcase_21 AC 265 ms
7,588 KB
testcase_22 AC 92 ms
6,492 KB
testcase_23 AC 238 ms
7,016 KB
testcase_24 AC 246 ms
7,072 KB
testcase_25 AC 15 ms
4,384 KB
testcase_26 AC 5 ms
4,380 KB
testcase_27 AC 3 ms
4,384 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 18 ms
4,384 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 18 ms
4,380 KB
testcase_33 AC 3 ms
4,380 KB
testcase_34 AC 2 ms
4,384 KB
testcase_35 AC 56 ms
5,308 KB
testcase_36 AC 67 ms
5,172 KB
testcase_37 AC 102 ms
6,584 KB
testcase_38 AC 123 ms
7,208 KB
testcase_39 AC 128 ms
6,500 KB
testcase_40 AC 112 ms
7,312 KB
testcase_41 WA -
testcase_42 AC 2 ms
4,384 KB
testcase_43 AC 2 ms
4,384 KB
testcase_44 AC 2 ms
4,384 KB
testcase_45 AC 2 ms
4,384 KB
testcase_46 AC 1 ms
4,384 KB
testcase_47 AC 2 ms
4,388 KB
testcase_48 AC 103 ms
6,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000



int main(){

	int N,P,Q;
	cin>>N>>P>>Q;
	
	vector<int> A(N);
	for(int i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	vector<int> ans;
	int ok = -1;
	int ng = N;
	
	while(ng-ok>1){
		int mid = (ok+ng)/2;
		vector<int> B;
		int p=-1,q=-1;
		for(int i=0;i<mid;i++){
			B.push_back(A[i]);
			if(A[i]==P)p=i;
			if(A[i]==Q)q=i;
		}
		vector<int> amari;
		for(int i=mid;i<N;i++)amari.push_back(A[i]);
		sort(amari.begin(),amari.end());
		auto it = upper_bound(amari.begin(),amari.end(),A[mid]);
		while(it!=amari.end()){
			if(p==-1||(*it)!=Q){
				B.push_back((*it));
				if((*it)==P)p = 100;
				amari.erase(it);
				break;
			}
			else{
				it++;
			}
		}
		int t = -1;
		for(int i=0;i<amari.size();i++){
			if(p==-1&&amari[i]==Q){
				t = amari[i];
			}
			else{
				B.push_back(amari[i]);
				if(amari[i]==P){
					p = 100;
					if(t!=-1)B.push_back(t);
				}
			}
		}
		p = -1,q = -1;
		for(int i=0;i<B.size();i++){
			if(B[i]==P)p = i;
			if(B[i]==Q)q = i;
		}
		/*
		cout<<mid<<endl;
		for(int i=0;i<B.size();i++){
			if(i!=0)cout<<' ';
			cout<<B[i];
		}
		cout<<endl;
		*/
		if(p<q&&B>A&&B.size()==N){
			ok = mid;
			ans = B;
		}
		else{
			ng = mid;
		}
	}
	
	if(ok==-1)cout<<-1<<endl;
	else{
		for(int i=0;i<ans.size();i++){
			if(i!=0)cout<<' ';
			cout<<ans[i];
		}
		cout<<endl;
	}
		
	
	return 0;
}
0