結果

問題 No.326 あみだますたー
ユーザー tottoripapertottoripaper
提出日時 2018-03-08 21:18:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,566 bytes
コンパイル時間 1,784 ms
コンパイル使用メモリ 172,960 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 12:21:10
合計ジャッジ時間 5,260 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 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 10 ms
6,940 KB
testcase_09 AC 9 ms
6,944 KB
testcase_10 AC 9 ms
6,940 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 3 ms
6,940 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int A[110], B[110];

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

    int N, K;
    std::cin >> N >> K;

    iota(A + 1, A + 1 + N, 1);

    vector<P> w;
    w.resize(K);
    
    for(int i=0;i<K;++i){
        std::cin >> fst(w[i]) >> snd(w[i]);
    }

    for(int i=K-1;i>=0;--i){
        swap(A[fst(w[i])], A[snd(w[i])]);
    }

    for(int i=1;i<=N;++i){
        std::cin >> B[i];
    }

    vector<P> v;
    for(int i=1;i<=N;++i){
        if(A[i] < B[i]){
            int j = A[i];
            while(j < B[i]){
                v.emplace_back(j, j + 1);
                int idx = find(A, A + 1 + N, j) - A, idx2 = find(A, A + 1 + N, j + 1) - A;
                swap(A[idx], A[idx2]);
                ++j;
            }
        }else if(B[i] < A[i]){
            int j = A[i];
            while(j > B[i]){
                v.emplace_back(j - 1, j);
                int idx = find(A, A + 1 + N, j - 1) - A, idx2 = find(A, A + 1 + N, j) - A;
                swap(A[idx], A[idx2]);
                --j;
            }
        }
    }

    std::cout << v.size() << std::endl;
    for(const auto &p : v){
        int x, y;
        tie(x, y) = p;

        std::cout << x << " " << y << std::endl;
    }
}
0