結果
問題 |
No.401 数字の渦巻き
|
ユーザー |
|
提出日時 | 2020-02-22 16:41:16 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 1,147 bytes |
コンパイル時間 | 12,214 ms |
コンパイル使用メモリ | 400,844 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-09 17:22:09 |
合計ジャッジ時間 | 13,649 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut maze: Vec<Vec<usize>> = vec![vec![0; n]; n]; let mut x: usize = 0; let mut y: usize = 0; for i in 1..=n*n { maze[y][x] = i; let at_top = (y == 0 && x < n-1) || (y > 0 && x < n-1 && maze[y-1][x] > 0 && maze[y][x+1] == 0); let at_right = !at_top && ((x == n-1 && y < n-1) || (x < n-1 && y < n-1 && maze[y][x+1] > 0 && maze[y+1][x] == 0)); let at_bottom = !at_top && !at_right && ((y == n-1 && x > 0) || (y < n-1 && x > 0 && maze[y+1][x] > 0 && maze[y][x-1] == 0)); let at_left = !at_top && !at_right && !at_bottom && ((x == 0 && y > 1) || (x > 0 && y > 0 && maze[y][x-1] > 0 && maze[y-1][x] == 0)); if at_top { x += 1; } else if at_right { y += 1; } else if at_bottom { x -= 1; } else if at_left { y -= 1; } } maze.iter().for_each(|line| { println!("{}", line.iter().map(|i| format!("{:03}", i)).collect::<Vec<String>>().join(" ")); }) }