結果
問題 | No.1051 PQ Permutation |
ユーザー | stoq |
提出日時 | 2020-03-26 21:20:44 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,761 bytes |
コンパイル時間 | 1,331 ms |
コンパイル使用メモリ | 170,432 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 19:29:31 |
合計ジャッジ時間 | 8,162 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
testcase_45 | RE | - |
testcase_46 | RE | - |
testcase_47 | RE | - |
testcase_48 | RE | - |
ソースコード
#include <bits/stdc++.h> using namespace std; //#include <boost/multiprecision/cpp_int.hpp> //using multiInt = boost::multiprecision::cpp_int; using ll = long long int; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; template <typename Q_type> using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>; const int MOD_TYPE = 1; const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353); const int INF = (int)1e9; const ll LINF = (ll)4e18; const ld PI = acos(-1.0); const ld EPS = 1e-11; #define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i) #define rep(i, n) REP(i, 0, n) #define MP make_pair #define MT make_tuple #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl #define possible(n) cout << ((n) ? "possible" : "impossible") << endl #define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl #define all(v) v.begin(), v.end() #define NP(v) next_permutation(all(v)) #define dbg(x) cerr << #x << ":" << x << endl; vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0}; vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0}; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(30) << setiosflags(ios::fixed); int n, p, q; cin >> n >> p >> q; int a[100010]; rep(i, n) cin >> a[i]; assert(2 <= n && n <= 100000); assert(1 <= p && p <= n); assert(1 <= q && q <= n); assert(p != q); int cnt[100010] = {}; rep(i, n) cnt[a[i]]++; for (int i = 1; i <= n; ++i) { assert(a[i] == 1); } //先頭x文字がAと一致 auto simulate = [&](int x) { if (x == -1) return true; bool used[100010] = {}; rep(i, x) { if (a[i] == q && !used[p]) return false; used[a[i]] = true; } if (used[p]) { REP(i, x, n) { if (a[i] > a[x]) return true; } return false; } else { REP(i, x, n) { if (a[i] > a[x] && a[i] != q) return true; } return false; } }; int lo = -2, hi = n; while (hi - lo > 1) { int mi = (lo + hi) / 2; if (simulate(mi)) lo = mi; else hi = mi; } int match = lo; dbg(match); if (match == -1) { cout << -1 << endl; return 0; } bool used[100010] = {}; int b[100010]; rep(i, match) { used[a[i]] = true; b[i] = a[i]; } if (used[p]) { for (int i = a[match] + 1; i <= n; i++) { if (!used[i]) { b[match] = i; used[i] = true; break; } } int bi = match + 1; for (int i = 1; i <= n && bi < n; i++) { if (!used[i]) { b[bi] = i; bi++; } } assert(bi == n); } else if (p < q) { for (int i = a[match] + 1; i <= n; i++) { if (!used[i] && i != q) { b[match] = i; used[i] = true; break; } } int bi = match + 1; for (int i = 1; i <= n && bi < n; i++) { if (!used[i]) { b[bi] = i; bi++; } } assert(bi == n); } else { int bi = match; for (int i = a[match] + 1; i <= n; i++) { if (!used[i] && i != q) { b[bi] = i; used[i] = true; bi++; if (i == p) { b[bi] = q; used[q] = true; bi++; } break; } } for (int i = 1; i <= n; i++) { if (!used[i] && i != q) { b[bi] = i; bi++; if (i == p) { b[bi] = q; bi++; } } } assert(bi == n); } rep(i, n) cout << b[i] << (i == n - 1 ? "\n" : " "); return 0; }