use itertools::Itertools; use proconio::input; macro_rules! chmax { ($a:expr,$b:expr) => { if $a < $b { $a = $b; true } else { false } }; } fn main() { input! { n: usize, k: usize, } if k == 0 { println!("-1"); return; } assert!(k <= n * n); let mut ans = vec![vec![0; n]; n]; let mut mx = n * n; let mut r = n * n - k; let mut x = n; if r >= n - 1 { x -= 1; r -= n - 1; while r >= n { x -= 1; r -= n; } } if x < n { ans[0][x] = mx; mx -= 1; } if r > 0 { ans[n - 1 - r][x - 1] = mx; } let mut z = 1; for i in 0..n { for j in 0..n { if ans[i][j] == 0 { ans[i][j] = z; z += 1; } } } assert!(check(&ans, k, n)); for r in ans { println!("{}", r.iter().join(" ")); } } fn check(a: &Vec>, k: usize, n: usize) -> bool { let mut mx = vec![vec![0; n]; n]; let mut cnt = 0; for i in 0..n { for j in 0..n { chmax!(mx[i][j], a[i][j]); if i > 0 { chmax!(mx[i][j], mx[i - 1][j]); } if j > 0 { chmax!(mx[i][j], mx[i][j - 1]); } if mx[i][j] == a[i][j] { cnt += 1; } } } cnt == k }