結果
問題 |
No.401 数字の渦巻き
|
ユーザー |
|
提出日時 | 2019-02-05 00:15:11 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 119 ms / 2,000 ms |
コード長 | 436 bytes |
コンパイル時間 | 257 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 12,160 KB |
最終ジャッジ日時 | 2024-12-26 06:28:24 |
合計ジャッジ時間 | 5,065 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
コンパイルメッセージ
Syntax OK
ソースコード
N = gets.to_i dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] x = y = 0 answer = Array.new(N) { Array.new(N) } 1.upto(N * N) do |i| answer[y][x] = format('%03d', i) next_x, next_y = x + dx.first, y + dy.first if next_x.negative? || next_x >= N || next_y.negative? || next_y >= N || answer[next_y][next_x] dx.rotate! dy.rotate! end x += dx.first y += dy.first end puts answer.map { |l| l.join(' ') }.join("\n")