結果

問題 No.326 あみだますたー
ユーザー cormorancormoran
提出日時 2016-06-28 17:58:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,899 bytes
コンパイル時間 1,623 ms
コンパイル使用メモリ 79,536 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 13:24:31
合計ジャッジ時間 2,691 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cassert>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<tuple>
#include<numeric>
using namespace std;

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl
// vector
template<class T> ostream& operator << (ostream &os , const vector<T> &v) {
    for(const T &t : v) os << "\t" << t; return os << endl;
}
template<class T> istream& operator >> (istream &is , vector<T> &v) {
    for(T &a : v) is >> a; return is;
}
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) {
    return os << "<" << v.first << " " << v.second << ">";
}



bool solve() {
    int N, K; cin >> N >> K;
    vector<int> X(K);
    rep(i, K) {
        int y;
        cin >> X[i] >> y;
        X[i]--;
    }
    vector<int> AA(N); cin >> AA;
    rep(i, N) AA[i]--;
    vector<int> A(N);
    rep(i, N) A[AA[i]] = i;
    
    
    vector<int> bar(N);
    rep(i, N) bar[i] = i;

    rep(i, K) swap(bar[X[i]], bar[X[i] + 1]);    
    // debug(bar);
    vector<int> ans;
    rep(i, N) {
        // iを合わせる
        vector<int> tmp;
        repeat(j, i, N) if(A[i] == bar[j]) {
            for(int k = j - 1; k >= i; k--) {
                swap(bar[k + 1], bar[k]);
                tmp.push_back(k);
            }
            break;
        }
        ans.insert(ans.end(), all(tmp));        
    }
    // debug(bar);
    cout << ans.size() << endl;
    for(int a : ans) {
        cout << a + 1 << " " << a + 2 << endl;
    }
    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(solve());
    return 0;
}
0