結果
問題 |
No.1087 転倒数の転倒数
|
ユーザー |
![]() |
提出日時 | 2020-06-19 22:42:00 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,187 bytes |
コンパイル時間 | 15,105 ms |
コンパイル使用メモリ | 405,200 KB |
実行使用メモリ | 7,936 KB |
最終ジャッジ日時 | 2024-07-03 15:14:01 |
合計ジャッジ時間 | 29,445 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 4 |
other | AC * 8 WA * 23 |
ソースコード
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(); }