結果

問題 No.401 数字の渦巻き
ユーザー suppy193suppy193
提出日時 2017-02-09 11:58:20
言語 Ruby
(3.2.2)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 554 bytes
コンパイル時間 60 ms
コンパイル使用メモリ 11,308 KB
実行使用メモリ 25,988 KB
最終ジャッジ日時 2023-08-26 17:47:40
合計ジャッジ時間 4,529 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
15,192 KB
testcase_01 AC 77 ms
15,156 KB
testcase_02 AC 71 ms
15,204 KB
testcase_03 AC 76 ms
15,052 KB
testcase_04 AC 76 ms
15,256 KB
testcase_05 AC 70 ms
15,144 KB
testcase_06 AC 76 ms
15,156 KB
testcase_07 AC 77 ms
15,252 KB
testcase_08 AC 73 ms
15,276 KB
testcase_09 AC 69 ms
15,228 KB
testcase_10 AC 72 ms
15,280 KB
testcase_11 AC 74 ms
15,276 KB
testcase_12 AC 70 ms
15,324 KB
testcase_13 AC 70 ms
15,448 KB
testcase_14 AC 69 ms
15,580 KB
testcase_15 AC 70 ms
15,456 KB
testcase_16 AC 71 ms
15,620 KB
testcase_17 AC 69 ms
15,600 KB
testcase_18 AC 70 ms
15,796 KB
testcase_19 AC 71 ms
16,372 KB
testcase_20 AC 72 ms
16,764 KB
testcase_21 AC 71 ms
17,132 KB
testcase_22 AC 71 ms
17,684 KB
testcase_23 AC 74 ms
18,316 KB
testcase_24 AC 72 ms
19,276 KB
testcase_25 AC 75 ms
20,136 KB
testcase_26 AC 78 ms
21,484 KB
testcase_27 AC 76 ms
22,884 KB
testcase_28 AC 76 ms
24,124 KB
testcase_29 AC 83 ms
25,988 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.strip.to_i

def make_spiral(n)
	if n == 0
		return []
	end
	if n == 1
		return [1]
	end
	spiral = []
	sub_spiral = make_spiral(n - 2)
	
	spiral += (1..n).to_a
	
	(0...n - 2).each do |i|
		spiral += [4 * n - 4 - i]
		(0...n - 2).each do |j|
			spiral += [sub_spiral[i * (n - 2) + j] + 4 * n - 4]	
		end
		spiral += [n + 1 + i]
	end
	
	(1..n).each do |i|
		spiral += [3 * n - 1 - i]
	end

	return spiral
end

spiral = make_spiral(n)
(0...n).each do |i|
	(0...n).each do |j|
		print "#{("00" + spiral[i * n + j].to_s)[-3, 3]} "
	end
	print "\n"
end
0