結果
問題 |
No.1051 PQ Permutation
|
ユーザー |
![]() |
提出日時 | 2020-05-08 23:00:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,775 bytes |
コンパイル時間 | 2,705 ms |
コンパイル使用メモリ | 201,268 KB |
最終ジャッジ日時 | 2025-01-10 09:12:34 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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 main() { int N, P, Q; cin >> N >> P >> Q; vector<int> A(N); cin >> A; set<int> s; bool p = false, q = false; IREP(i, N) { int T = A[i]; if (T == P) p = true; if (T == Q) q = true; s.insert(T); if (p and q and s.size() == 2 and P > Q) { A[i - 2] = P, A[i - 1] = Q; output(A); } if (p and q and *prev(s.end()) > A[i] and s.size() > 2) { int x = *s.upper_bound(T); if (x == Q and p) x = *next(s.upper_bound(T)); A[i] = x; s.erase(x); if (x == P) p = false; FOR(j, i + 1, N) { A[j] = *s.begin(); if (A[j] == Q and p) A[j] = *next(s.begin()); s.erase(A[j]); if (A[j] == P) p = false; } output(A); } } puts("-1"); }