結果

問題 No.326 あみだますたー
ユーザー maimai
提出日時 2016-06-25 16:37:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,017 bytes
コンパイル時間 1,740 ms
コンパイル使用メモリ 166,824 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-25 13:19:47
合計ジャッジ時間 3,053 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 4 ms
6,940 KB
testcase_10 AC 4 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 3 ms
6,948 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 3 ms
6,944 KB
testcase_25 AC 3 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 3 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;
typedef long long int ll;

int main(){
    int i,j,k,l;
    int m,n;
    
    cin>>n>>m;
    
    vector<int> vo(n);
    iota(vo.begin(),vo.end(),1);
    
    for (i=0;i<m;i++){
        scanf("%d%d",&k,&l);
        swap(vo[k-1],vo[l-1]);
    }
    
    vector<int> vi(n);
    for (i=0;i<n;i++){
        scanf("%d",&k);
        vi[i]=k;
    }
    vector<int> va(n);
    for (i=0;i<n;i++)
        va[vi[i]-1]=i+1;
    
    //for (int e:vo)cout<<e<<" ";cout<<endl;
    //for (int e:va)cout<<e<<" ";cout<<endl;
    
    list<int> q;
    
    for (i=0;i<(n-1);i++){
        for (j=n;i<j;j--){
            if (vo[j]==va[i]){
                swap(vo[j],vo[j-1]);
                q.push_back(j);
            }
        }
    }
    
    cout<<q.size()<<endl;
    while (!q.empty()){
        printf("%d %d\n",q.front(),q.front()+1);
        q.pop_front();
    }
    
    return 0;
}
0