結果

問題 No.1051 PQ Permutation
ユーザー wkwk
提出日時 2020-05-08 23:11:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 9,118 bytes
コンパイル時間 1,845 ms
コンパイル使用メモリ 171,820 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 20:00:12
合計ジャッジ時間 5,075 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
5,376 KB
testcase_12 WA -
testcase_13 AC 2 ms
5,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 39 ms
5,376 KB
testcase_36 AC 39 ms
5,376 KB
testcase_37 WA -
testcase_38 AC 81 ms
5,376 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
using namespace std;

long modpow(long a, long n, long mod) {
    long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long modinv(long a, long mod) {
    return modpow(a, mod - 2, mod);
}

struct compare1 { 
    bool operator()(const pair<long, long>& value,  
                                const long& key) 
    { 
        return (value.first < key); 
    } 
    bool operator()(const long& key,  
                    const pair<long, long>& value) 
    { 
        return (key < value.first); 
    } 
};

struct RMQ {
    vector<int> a;
    int inf = 2000000000; // 2*10^9
    int n = 1;

    RMQ(int n_ = 1){
        init(n_);
    }

    void init(int n_ = 1){
        while(n < n_) n *= 2;
        a.resize(2*n-1);
        REP(i, 2*n-1) a[i] = inf;
    }
    //k番目の値(0-indexed)をbに変更
    void update(int k, int b){
        k += n-1;
        a[k] = b;
        while(k > 0){
            k = (k-1)/2;
            a[k] = min(a[2*k+1], a[2*k+2]);
        }
    }
    //[c,b)の最小値を返す際に呼ぶ関数
    int query_first(int c, int b){
        return query(c, b, 0, 0, n);
    }
    //k : 節点番号, l, rはその接点が[l, r)に対応することを示す
    int query(int c, int b, int k, int l, int r){
        if(r <= c || b <= l) return inf;
        if(c <= l && r <= b) return a[k];
        else{
            int vl = query(c, b, k*2+1, l, (l+r)/2);
            int vr = query(c, b, k*2+2, (l+r)/2, r);
            return min(vl, vr);
        }
    }
};

struct UnionFind {
    vector<int> par;
    vector<int> rank;

    UnionFind(int n = 1){
        init(n);
    }

    void init(int n = 1){
        par.resize(n);
        rank.resize(n);
        REP(i, n) par[i] = i, rank[i] = 0; 
    }

    int root(int x){
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y){
        return root(x) == root(y);
    }

    bool merge(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return false;
        if(rank[x] < rank[y]) swap(x, y);
        if(rank[x] == rank[y]) rank[x]++;
        par[y] = x;
        return true;
    }
};

template<class Abel> struct weightedUnionFind{
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    weightedUnionFind(int n = 1, Abel SUM_UNITY = 0){
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0){
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        REP(i, n) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY; 
    }

    int root(int x){
        if(par[x] == x) return x;
        else{
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x){
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y){
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w){
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if(x == y) return false;
        if(rank[x] < rank[y]) swap(x, y), w = -w;
        if(rank[x] == rank[y]) rank[x]++;
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y){
        return weight(y) - weight(x);
    }
};

/*
void dijkstra(int s, int V, Graph &G, long* d){
    priority_queue<P, vector<P>, greater<P>> pque;
    fill(d, d + V, INF);
    d[s] = 0;
    pque.push(P(0, s));

    while(!pque.empty()){
        P p = pque.top(); pque.pop();
        int now = p.second;
        if(d[now] < p.first) continue;
        REP(i, G[now].size()){
            Edge e = G[now][i];
            if(d[e.to] > d[now] + e.weight){
                d[e.to] = d[now] + e.weight;
                pque.push(P(d[e.to], e.to));
            }
        }
    }
}
*/

int GCD(int a, int b){
    if(b == 0) return a; 
    if(a < b) return GCD(b, a);
    else return GCD(b, a%b);
}

struct BIT{
    vector<long> dat;
    int n = 1;

    BIT(int nn = 1){
        init(nn);
    }

    void init(int nn = 1){
        while(n < nn) n *= 2;
        dat.resize(n+1);
        REP(i, n+1) dat[i] = 0l;
    }
    //1-indexed!!!!
    //index iにx加える
    void add(int i, long x){
        while(i <= n){
            dat[i] += x;
            i += (i&(-i));
        }
    }
    //1-indexed!!!!!
    //index 1-iまでの和を求める
    long get_sum(int i){
        long ans = 0l;
        while(i > 0){
            ans += dat[i];
            i -= (i & (-i));
        }
        return ans;
    }
};

//{0, 1, 2, ..., n-1}までの中からk個の要素を持つ部分集合についての処理を行う
int next_combination(int sub){
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}
//main関数内で
//bit = (1<<k)-1;
//for(; bit < (1<<n); bit = next_combination(bit))
// REP(i, n) if(bit & (1<<i)) でbitの中で選ばれている要素iを全部取得できる
//bitset<8>(bit)でbitを8桁の2進数で表示できる

//BellmanFord
struct Edge{
    int from, to;
    long cost;
    Edge(int f, int t, long c){
        from = f;
        to = t;
        cost = c;
    }
};

struct BellmanFord{
    vector<Edge> es;
    vector<long> d;
    int E, V; // E 辺 V 頂点
    long inf = 1000000000000000000;

    BellmanFord(int ee=1, int vv=1){
        E = ee;
        V = vv;
        d.resize(vv);
    }

    void update(int from, int to, long cost){
        es.push_back(Edge(from, to, cost));
    }

    void shortest_path(int start){
        REP(i, V) d[i] = inf;
        d[start] = 0l;
        while(true){
            bool upd = false;
            REP(i, E){
                Edge e = es[i];
                if(d[e.from] != inf && d[e.to] > d[e.from] + e.cost){
                    d[e.to] = d[e.from] + e.cost;
                    upd = true;
                }
            }
            if(!upd) break;
        }
        cout << -d[V-1] << endl;

    }

    //true : there is a negative loop.
    //false : there is NOT a negative loop.
    bool find_negative_loop(){
        REP(i, V) d[i] = 0l;
        REP(i, V){
            REP(j, E){
                Edge e = es[j];
                if(d[e.to] > d[e.from] + e.cost){
                    d[e.to] = d[e.from] + e.cost;
                    if(i==V-1) return true;
                }
            }
        }
        return false;
    }

    //true : there is a negative loop including start.
    //false : there is NOT a negative loop including start.
    bool find_negative_loop_from_start(int start){
        REP(i, V) d[i] = inf;
        d[start] = 0l;
        int itr = 0;
        while(true){
            bool upd = false;
            REP(i, E){
                Edge e = es[i];
                if(d[e.from] != inf && d[e.to] > d[e.from] + e.cost){
                    d[e.to] = d[e.from] + e.cost;
                    upd = true;
                }
            }
            if(!upd) break;
            itr++;
            if(itr == V) break;
        }
        if(itr == V) return true;
        else return false;
    }

};

int N, P, Q;
bool change(int *A){
    return true;
}

int main()
{
    cin >> N >> P >> Q;
    int A[200005];
    int ans[200005];
    REP(i, N) cin >> A[i];
    if(A[0] == P){
        REP(i, N) cout << A[i] << " ";
        cout << endl;
    }else if(A[0] == Q){
        if(A[0] == N) cout << -1 << endl;
        else{
            ans[0] = (A[0] + 1);
            int ind = 1;
            for(int i=1;i<P;i++){
                if(i != ans[0] && i != Q){
                    ans[ind] = i;
                    ind++;
                }
            }
            ans[ind] = P;
            ind++;
            for(int i=P+1; i<=N; i++){
                if(i < Q && i != ans[0]){
                    ans[ind] = i;
                    ind++;
                }
            }
            ans[ind] = Q;
            ind++;
            for(int i = max(P,Q)+1; i<=N;i++){
                if(i != ans[0]){
                    ans[ind] = i;
                    ind++;
                }
            }
            REP(i, N) cout << ans[i] << " ";
            cout << endl;
        }
    }else{
        if(change(A)){
            ans[0] = (A[0] + 1);
            int ind = 1;
            for(int i=1;i<P;i++){
                if(i != ans[0] && i != Q){
                    ans[ind] = i;
                    ind++;
                }
            }
            ans[ind] = P;
            ind++;
            for(int i=P+1; i<=N; i++){
                if(i < Q && i != ans[0]){
                    ans[ind] = i;
                    ind++;
                }
            }
            ans[ind] = Q;
            ind++;
            for(int i = max(P,Q)+1; i<=N;i++){
                if(i != ans[0]){
                    ans[ind] = i;
                    ind++;
                }
            }
            REP(i, N) cout << ans[i] << " ";
            cout << endl;
        }

    }

    return 0;
}

0