結果

問題 No.326 あみだますたー
ユーザー Lay_ecLay_ec
提出日時 2015-12-19 00:28:26
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,300 bytes
コンパイル時間 746 ms
コンパイル使用メモリ 90,612 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-10-14 14:09:52
合計ジャッジ時間 4,742 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

int main(){

    int n,k;
    cin>>n>>k;
    
    vector<int> a(n),tar(n);
    for(int i=0;i<n;i++) a[i]=i+1;
    
    for(int i=0;i<k;i++){
        int x,y;
        cin>>x>>y;
        swap(a[x-1],a[y-1]);
    }
    
    for(int i=0;i<n;i++) cin>>tar[i];
    
    vector<pair<int,int> > ans;
    for(int i=0;i<n;i++){
        if(tar[i]==a[i]) continue;
        int pos=0;
        for(int j=1;j<n;j++){
            if(tar[i]==a[j]){
                pos=j;
                break;
            }
        }

        int x=i;

        if(pos<x){
            for(int j=pos;j+1<=x;j++){
                ans.push_back(make_pair(j+1,j+1+1));
                swap(a[j],a[j+1]);
            }
        }else{
            for(int j=pos;j-1>=x;j--){
                ans.push_back(make_pair(j-1+1,j+1));
                swap(a[j-1],a[j]);            
            }
        }
        
    }
    
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++) cout<<ans[i].first<<" "<<ans[i].second<<endl;


    return 0;

}
0