結果

問題 No.326 あみだますたー
ユーザー btkbtk
提出日時 2015-12-22 22:03:50
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 830 bytes
コンパイル時間 2,260 ms
コンパイル使用メモリ 164,004 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 22:48:21
合計ジャッジ時間 6,353 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 2 ms
4,348 KB
testcase_06 RE -
testcase_07 AC 2 ms
4,348 KB
testcase_08 WA -
testcase_09 RE -
testcase_10 WA -
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> V;
int main() {
    int N,K;
    cin>>N>>K;
    V A(N);iota(A.begin(),A.end(),1);
    for(int i = 0; i < K; i++){
        int x,y;
        cin>>x>>y;
        swap(A[x-1],A[y-1]);
    }
    V B(N);
    V X,Y;
    for(int i = 0; i < N; i++){
        int t;cin>>t;
        B[t-1]=i+1;
    }
    for(int i=0;i<N;i++){
        if(A[i]!=B[i])
        for(int j = i+1; j < N; j++)
            if(A[j]==B[i]){
                for(int k=j;k>i;k--){
                    X.push_back(k);
                    Y.push_back(k+1);
                    swap(A[i],A[j]);
                }
            }
    }
    for(int i = 0; i < N; i++)if(A[i]!=B[i])return 1;
    int L=X.size();
    cout<<L<<endl;;
    for(int i = 0; i < L; i++)
    cout<<X[i]<<" "<<Y[i]<<endl;

    return 0;
}
0