結果

問題 No.1087 転倒数の転倒数
ユーザー akakimidoriakakimidori
提出日時 2020-06-19 22:42:00
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,187 bytes
コンパイル時間 2,975 ms
コンパイル使用メモリ 151,324 KB
実行使用メモリ 7,860 KB
最終ジャッジ日時 2023-09-16 14:56:43
合計ジャッジ時間 19,220 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 73 ms
7,828 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1 ms
4,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

fn gen_perm(n: usize, mut inv: usize) -> Vec<usize> {
    let mut q = (0..n).collect::<std::collections::VecDeque<usize>>();
    let mut ans = vec![];
    for i in 1..=n {
        if n <= inv + i {
            inv -= n - i;
            ans.push(q.pop_back().unwrap());
        } else {
            ans.push(q.pop_front().unwrap());
        }
    }
    ans
}

fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let k: usize = it.next().unwrap().parse().unwrap();
    if k > n * (n - 1) {
        println!("No");
        return;
    }
    println!("Yes");
    let x = k / 2;
    let y = k - x;
    let a = gen_perm(n, x);
    let b = gen_perm(n, y);
    let mut ans = vec![vec![0; n]; n];
    for i in 0..n {
        for j in 0..n {
            if a[i] == b[j] {
                ans[i][j] = 1;
            }
        }
    }
    let mut s = String::new();
    for a in ans {
        for a in a {
            s.push_str(&format!("{} ", a));
        }
        s.pop();
        s.push('\n');
    }
    print!("{}", s);
}

fn main() {
    run();
}
0