結果

問題 No.3726 Flawless Flow
コンテスト
ユーザー 👑 kencho
提出日時 2026-07-01 12:28:30
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 9 ms / 2,000 ms
+ 152µs
コード長 870 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,114 ms
コンパイル使用メモリ 333,264 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2026-09-19 12:31:23
合計ジャッジ時間 5,841 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 59
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

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

    int n;
    cin >> n;
    vector<int> a(n), b(n), rankInB(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
        rankInB[b[i]] = i;
    }

    vector<int> row = a;
    auto printRow = [&]() {
        for (int i = 0; i < n; i++) {
            if (i > 0) {
                cout << ' ';
            }
            cout << row[i];
        }
        cout << '\n';
    };

    printRow();
    for (int phase = 0; phase < n; phase++) {
        int start = phase % 2;
        for (int i = start; i + 1 < n; i += 2) {
            if (rankInB[row[i]] > rankInB[row[i + 1]]) {
                swap(row[i], row[i + 1]);
            }
        }
        printRow();
    }

    return 0;
}
0