結果

問題 No.326 あみだますたー
ユーザー cormorancormoran
提出日時 2016-06-28 17:29:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,791 bytes
コンパイル時間 755 ms
コンパイル使用メモリ 79,656 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-20 03:42:01
合計ジャッジ時間 3,979 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 9 ms
6,940 KB
testcase_09 AC 8 ms
6,944 KB
testcase_10 AC 8 ms
6,940 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<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;
    int yyy;
    vector<int> X(K);
    rep(i, K) cin >> X[i] >> yyy;
    rep(i, K) X[i]--;
    vector<int> A(N); cin >> A;
    rep(i, N) A[i]--;
    
    vector<int> bar(N);
    rep(i, N) bar[i] = i;

    rep(i, K) swap(bar[X[i]], bar[X[i] + 1]);    

    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);
            }
        }
        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