結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 2 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 361 ms
7,408 KB
testcase_16 AC 348 ms
7,416 KB
testcase_17 WA -
testcase_18 AC 92 ms
6,508 KB
testcase_19 AC 91 ms
6,612 KB
testcase_20 AC 253 ms
6,968 KB
testcase_21 AC 267 ms
7,544 KB
testcase_22 AC 90 ms
6,492 KB
testcase_23 AC 240 ms
7,060 KB
testcase_24 AC 248 ms
7,016 KB
testcase_25 AC 15 ms
4,376 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 19 ms
4,376 KB
testcase_31 AC 5 ms
4,376 KB
testcase_32 AC 19 ms
4,380 KB
testcase_33 AC 3 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 56 ms
5,176 KB
testcase_36 AC 67 ms
5,196 KB
testcase_37 AC 104 ms
6,528 KB
testcase_38 AC 127 ms
7,412 KB
testcase_39 AC 132 ms
6,648 KB
testcase_40 AC 114 ms
7,172 KB
testcase_41 WA -
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 1 ms
4,384 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 104 ms
6,516 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){
			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