結果
| 問題 |
No.1051 PQ Permutation
|
| コンテスト | |
| ユーザー |
auaua
|
| 提出日時 | 2020-05-08 23:20:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,746 bytes |
| コンパイル時間 | 1,729 ms |
| コンパイル使用メモリ | 176,536 KB |
| 実行使用メモリ | 16,520 KB |
| 最終ジャッジ日時 | 2024-07-05 20:03:00 |
| 合計ジャッジ時間 | 6,761 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 WA * 24 |
ソースコード
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
ll n,p,q;cin>>n>>p>>q;
vector<ll>a(n);
rep(i,n){
cin>>a[i];
}
set<ll>st;
vector<ll>b(0);
rep(i,n){
st.insert(i+1);
}
ll cnt=0;
st.erase(p);
st.erase(q);
bool d=0;
rep(i,n){
if(d){
auto itr=st.lower_bound(0);
if(itr==st.end()){
if(cnt==0){
b.pb(p);
cnt++;
}else if(cnt==1){
b.pb(q);
cnt++;
}
}else{
if(cnt==0){
if(p<*itr){
b.pb(p);
cnt++;
}else{
b.pb(*itr);
st.erase(*itr);
}
}else if(cnt==1){
if(q<*itr){
b.pb(q);
cnt++;
}else{
b.pb(*itr);
st.erase(*itr);
}
}else{
b.pb(*itr);
st.erase(*itr);
}
}
continue;
}
auto itr=st.lower_bound(a[i]);
if(itr==st.end()){
if(cnt==0){
b.pb(p);
cnt++;
}else if(cnt==1){
b.pb(q);
cnt++;
}
}else{
if(cnt==1){
if(q>=a[i]&&q<*itr){
b.pb(q);
cnt++;
}else{
b.pb(*itr);
st.erase(*itr);
}
}else if(cnt==0){
if(p>=a[i]&&p<*itr){
b.pb(p);
cnt++;
}else{
b.pb(*itr);
st.erase(*itr);
}
}else{
b.pb(*itr);
st.erase(*itr);
}
}
if(b[i]>a[i])d=1;
}
bool f=1;
if(b.size()<n){
f=0;
}else{
bool k=0;
rep(i,n){
if(a[i]<b[i]){
k=1;
break;
}
if(a[i]>b[i]){
k=0;
break;
}
}
f&=k;
}
if(f){
rep(i,n){
cout<<b[i]<<' ';
}
cout<<endl;
}else{
cout<<-1<<endl;
}
}
auaua