結果

問題 No.326 あみだますたー
ユーザー cormoran
提出日時 2016-06-28 17:58:16
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,899 bytes
コンパイル時間 781 ms
コンパイル使用メモリ 79,304 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-08 00:24:43
合計ジャッジ時間 2,040 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

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