結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
wonda_t_coffee
|
| 提出日時 | 2020-02-05 10:43:56 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 88 ms / 2,000 ms |
| コード長 | 404 bytes |
| コンパイル時間 | 465 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 12,416 KB |
| 最終ジャッジ日時 | 2024-09-22 06:06:33 |
| 合計ジャッジ時間 | 3,931 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
コンパイルメッセージ
Syntax OK
ソースコード
n = gets.chomp.to_i
mat = Array.new(n){Array.new(n){nil}}
di = 0
d = [[1, 0], [0, 1], [-1, 0], [0, -1]]
x, y = 0, 0
(n*n).times do |i|
mat[y][x] = i + 1
dx, dy = d[di]
nx, ny = x + dx, y + dy
if nx < 0 || nx >= n || ny < 0 || ny >= n || mat[ny][nx]
di = (di + 1) % 4
end
x = x + d[di][0]
y = y + d[di][1]
end
mat.each do |row|
puts row.map{|n| n.to_s.rjust(3, '0')}.join(' ')
end
wonda_t_coffee