結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,356 KB
testcase_06 AC 3 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 9 ms
4,356 KB
testcase_09 AC 9 ms
4,352 KB
testcase_10 AC 11 ms
4,352 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 #

#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream &operator << (ostream &os, const vector<T> &);
template<size_t n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, const tuple<T...> &){}
template<size_t n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream &os, const tuple<T...> &t){
    os << (n == 0 ? "" : " ") << get<n>(t); _ot<n+1>(os, t);
}
template<class...T> ostream &operator << (ostream &os, const tuple<T...> &t){
    _ot<0>(os, t); return os;
}
template<class T, class U> ostream & operator << (ostream &os, const pair<T,U> &p){
    return os << "(" << p.first << ", " << p.second << ") ";
}
template<class T> ostream &operator << (ostream &os, const vector<T> &v){
    for(size_t i = 0; i < v.size(); i++) os << v[i] << (i + 1 == v.size() ? "" : ", "); return os;
}
#ifdef DEBUG
#define dump(...) (cerr << #__VA_ARGS__ << " = " << make_tuple(__VA_ARGS__) \
                   << " (L : " << __LINE__ << ")" << endl)
#else
#define dump(...)
#endif
#define all(c) begin(c), end(c)
#define range(i,a,b) for(int i = a; i < (int)(b); i++)
#define rep(i,b) range(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
using ll = long long;
// #define int ll
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
void fastios(){ ios_base::sync_with_stdio(0); cin.tie(0); }
int const mod = 1000000007;
auto const inf = numeric_limits<int>::max()/8;

vector<pii> bubblesort(int *l, int *r, function<bool(int,int)> f){
    vector<pii> ans;
    int n = r-l;
    bool end;
    while(1){
        end = true;
        rep(i,n-1){
            if(!f(l[i], l[i+1])){
                swap(l[i], l[i+1]);
                ans.eb(i+1,i+2);
                end = false;
            }
        }
        if(end) break;
    }
    return ans;
}

int l;
int main(){
    int n;
    while(cin >> n && n){
        int cur[6010];
        rep(i,n) cur[i] = i;
        int l;
        cin >> l;
        rep(i,l){
            int x,y;
            cin >> x >> y;
            --x, --y;
            swap(cur[x], cur[y]);
        }
        int w[6010];
        int dst[6010];
        rep(i,n){
            cin >> dst[i];
            w[dst[i]-1] = i;
        }
        auto ans = bubblesort(cur, cur+n, [&](int a, int b){
                return w[a] < w[b];
            });
        cout << ans.size() << endl;
        rep(i,ans.size()) cout << ans[i].first << ' ' << ans[i].second << endl;
    }
}
0