結果

問題 No.326 あみだますたー
ユーザー face4
提出日時 2018-11-06 22:06:08
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 752 bytes
コンパイル時間 618 ms
コンパイル使用メモリ 72,264 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-20 20:36:41
合計ジャッジ時間 1,874 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin >> n >> k;

    int v[n];
    for(int i = 0; i < n; i++)  v[i] = i;

    int x, y;
    for(int i = 0; i < k; i++){
        cin >> x >> y;
        swap(v[--x], v[--y]);
    }

    int a[n];
    for(int i = 0; i < n; i++)  cin >> a[i];

    vector<pair<int,int>> ans;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n-1-i; j++){
            if(a[v[j]] > a[v[j+1]]){
                ans.push_back({j+1, j+2});
                swap(v[j], v[j+1]);
            }
        }
    }

    cout << ans.size() << endl;

    for(pair<int,int> p : ans)  cout << p.first << " " << p.second << endl;

    return 0;
}
0