結果

問題 No.1051 PQ Permutation
ユーザー 👑 hitonanodehitonanode
提出日時 2020-05-08 23:00:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,775 bytes
コンパイル時間 3,773 ms
コンパイル使用メモリ 207,456 KB
実行使用メモリ 13,544 KB
最終ジャッジ日時 2023-09-19 08:00:19
合計ジャッジ時間 7,201 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 166 ms
13,360 KB
testcase_16 AC 154 ms
12,824 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 93 ms
9,904 KB
testcase_21 AC 97 ms
10,152 KB
testcase_22 WA -
testcase_23 AC 97 ms
9,772 KB
testcase_24 AC 92 ms
9,732 KB
testcase_25 AC 6 ms
4,380 KB
testcase_26 WA -
testcase_27 AC 2 ms
4,380 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 7 ms
4,376 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 8 ms
4,376 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 50 ms
8,384 KB
testcase_37 AC 76 ms
13,320 KB
testcase_38 AC 106 ms
13,544 KB
testcase_39 AC 72 ms
13,372 KB
testcase_40 AC 63 ms
8,852 KB
testcase_41 AC 64 ms
8,852 KB
testcase_42 WA -
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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");
}
0