結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2020-07-06 12:34:26 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 89 ms / 2,000 ms |
| コード長 | 488 bytes |
| コンパイル時間 | 370 ms |
| コンパイル使用メモリ | 7,296 KB |
| 実行使用メモリ | 12,416 KB |
| 最終ジャッジ日時 | 2024-09-24 17:11:39 |
| 合計ジャッジ時間 | 3,491 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
コンパイルメッセージ
Main.rb:10: warning: assigned but unused variable - num Syntax OK
ソースコード
N = gets.to_i
ans = Array.new(N) { Array.new(N) }
visited = Array.new(N) { Array.new(N) }
DY = [-1, 0, 1, 0]
DX = [0, 1, 0, -1]
direct = 1
y = 0
x = 0
num = 1
(1..N * N).each do |n|
ans[y][x] = "%03d" % n
visited[y][x] = true
ny = y + DY[direct]
nx = x + DX[direct]
if ny < 0 || nx < 0 || N <= ny || N <= nx || visited[ny][nx]
direct = (direct + 1) % 4
ny = y + DY[direct]
nx = x + DX[direct]
end
y = ny
x = nx
end
puts ans.map { |row| row.join(' ') }
siman