結果
問題 |
No.401 数字の渦巻き
|
ユーザー |
|
提出日時 | 2024-05-23 15:44:36 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 574 bytes |
コンパイル時間 | 14,712 ms |
コンパイル使用メモリ | 389,132 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-20 18:51:39 |
合計ジャッジ時間 | 15,031 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
fn main() { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let n: usize = s.trim().parse().unwrap(); let (mut x, mut y, mut p, mut q) = (0i16, 0i16, 1i16, 0i16); let mut a = vec![0; n * n]; for i in 1..=n * n { a[(x + y * n as i16) as usize] = i; if x + p >= n as i16 || y + q >= n as i16 || a[(x + p + (y + q) * n as i16) as usize] != 0 { (p, q) = (-q, p); } x += p; y += q; } a.chunks(n).for_each(|r| { println!( "{}", r.iter() .map(|&x| format!("{:03}", x)) .collect::<Vec<_>>() .join(" ") ) }); }