結果

問題 No.3726 Flawless Flow
コンテスト
ユーザー shingo0909
提出日時 2026-09-19 14:42:38
言語 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
結果
WA  
実行時間 -
コード長 1,218 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,082 ms
コンパイル使用メモリ 353,180 KB
実行使用メモリ 9,924 KB
最終ジャッジ日時 2026-09-19 14:42:56
合計ジャッジ時間 5,817 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 51 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    vector<vector<bool>> v(n + 1, vector<bool>(n + 1));
    rep(i, n) rep(j, n) {
        if (i > j)
            continue;
        v[b[i]][b[j]] = true;
    }
    rep(i, n) cout << a[i] << " ";
    cout << endl;
    vector<int> p;
    deque<int> q;
    rep(i, n - 1) q.push_back(i);
    while (true) {
        p.push_back(q.front());
        q.pop_front();
        if (q.empty())
            break;
        p.push_back(q.back());
        q.pop_back();
        if (q.empty())
            break;
    }
    rep(_, n) {
        set<int> st;
        for (int j : p) {
            if (!v[a[j]][a[j + 1]]) {
                if (st.contains(j - 1))
                    continue;
                if (st.contains(j + 1))
                    continue;
                swap(a[j], a[j + 1]);
                st.insert(j);
            }
        }
        rep(i, n) cout << a[i] << " ";
        cout << endl;
    }
    return 0;
}
0