結果

問題 No.3726 Flawless Flow
コンテスト
ユーザー pt9999
提出日時 2026-11-15 22:06:34
言語 Fix
(1.6.1 + cp-library + minilib)
コンパイル:
fix_c _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 851 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 7,279 ms
コンパイル使用メモリ 264,968 KB
実行使用メモリ 9,920 KB
最終ジャッジ日時 2026-11-15 22:06:47
合計ジャッジ時間 13,654 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 48 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

module Main;

import CPLib.IO;

main: IO ();
main = (
    let n = *read_i;
    let a = *read_is(n);
    let b = *read_is(n);
    let ord = range(0, n).fold(
        Array::fill(n+1, 0), |i, ord|
        ord.set(b.@(i), i)
    );
    let rows = range(0, n).fold(
        [a], |_, rows|
        let a = rows.get_last.as_some;
        let b = loop(
            (a, 0), |(b, i)|
            if i >= n { break $ b };
            if i+1 < n && ord.@(b.@(i)) > ord.@(b.@(i+1)) {
                let (x, y) = (b.@(i), b.@(i+1));
                let b = b.set(i, y).set(i+1, x);
                continue $ (b, i+2)
            };
            continue $ (b, i+1)
        );
        rows.push_back(b)
    );
    if rows.get_last.as_some != b {
        println $ "-1"
    };
    rows.to_iter.map(|row| row.to_iter.map(to_string).join(" ")).join("\n").println
);

0