結果
| 問題 |
No.1051 PQ Permutation
|
| コンテスト | |
| ユーザー |
hitonanode
|
| 提出日時 | 2020-05-08 23:02:01 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,837 bytes |
| コンパイル時間 | 2,268 ms |
| コンパイル使用メモリ | 202,804 KB |
| 最終ジャッジ日時 | 2025-01-10 09:13:27 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 WA * 17 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
void output(vector<int> v)
{
for (auto x : v) cout << x << ' ';
cout << '\n';
exit(0);
}
int in()
{
int x;
cin >> x;
return x;
}
int main()
{
const int N = in(), P = in(), Q = in();
vector<int> A(N);
cin >> A;
set<int> s;
bool fp = false, fq = false;
IREP(i, N)
{
if (A[i] == P) fp = true;
if (A[i] == Q) fq = true;
s.insert(A[i]);
if (fp and fq and s.size() == 2 and P > Q)
{
A[N - 2] = P, A[N - 1] = Q;
output(A);
}
if (fp and fq and *prev(s.end()) > A[i] and s.size() > 2)
{
int x = *s.upper_bound(A[i]);
if (x == Q and fp) x = *next(s.upper_bound(A[i]));
A[i] = x;
s.erase(x);
if (x == P) fp = false;
FOR(j, i + 1, N)
{
A[j] = *s.begin();
if (A[j] == Q and fp) A[j] = *next(s.begin());
s.erase(A[j]);
if (A[j] == P) fp = false;
}
output(A);
}
}
puts("-1");
}
hitonanode