結果

問題 No.401 数字の渦巻き
ユーザー LeonardoneLeonardone
提出日時 2016-07-23 04:15:00
言語 Ruby
(3.3.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 1,092 bytes
コンパイル時間 229 ms
コンパイル使用メモリ 11,460 KB
実行使用メモリ 15,492 KB
最終ジャッジ日時 2023-08-06 11:18:28
合計ジャッジ時間 4,704 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
15,112 KB
testcase_01 AC 80 ms
15,252 KB
testcase_02 AC 80 ms
15,300 KB
testcase_03 AC 81 ms
15,156 KB
testcase_04 AC 78 ms
15,144 KB
testcase_05 AC 80 ms
15,264 KB
testcase_06 AC 78 ms
15,024 KB
testcase_07 AC 79 ms
15,028 KB
testcase_08 AC 78 ms
15,292 KB
testcase_09 AC 80 ms
15,216 KB
testcase_10 AC 80 ms
15,140 KB
testcase_11 AC 80 ms
15,208 KB
testcase_12 AC 80 ms
15,100 KB
testcase_13 AC 80 ms
15,340 KB
testcase_14 AC 79 ms
15,304 KB
testcase_15 AC 80 ms
15,252 KB
testcase_16 AC 82 ms
15,360 KB
testcase_17 AC 83 ms
15,312 KB
testcase_18 AC 84 ms
15,492 KB
testcase_19 AC 82 ms
15,464 KB
testcase_20 AC 82 ms
15,392 KB
testcase_21 AC 81 ms
15,388 KB
testcase_22 AC 81 ms
15,168 KB
testcase_23 AC 83 ms
15,424 KB
testcase_24 AC 81 ms
15,440 KB
testcase_25 AC 81 ms
15,408 KB
testcase_26 AC 80 ms
15,368 KB
testcase_27 AC 81 ms
15,324 KB
testcase_28 AC 82 ms
15,168 KB
testcase_29 AC 85 ms
15,364 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# yukicoder My Practice
# author: Leonardone @ NEETSDKASU
############################################################
def gs() gets.chomp end
def gi() gets.to_i end
def gf() gets.to_f end
def gss() gs.split end
def gis() gss.map(&:to_i) end
def gfs() gss.map(&:to_f) end
def nmapf(n,f) n.times.map{ __send__ f } end
def ngs(n) nmapf n,:gs end
def ngi(n) nmapf n,:gi end
def ngss(n) nmapf n,:gss end
def ngis(n) nmapf n,:gis end
def arr2d(h,w,v=0) h.times.map{[v] * w} end
def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end
def nsum(n) n * (n + 1) / 2 end
def vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end
MV = [[0, 1], [1, 0], [0, -1], [-1, 0]]
############################################################

N = gi

a = arr2d N, N

y = 0
x = 0

m = 0
dy, dx = MV[m]

a[0][0] = 1
c = 2

while c <= N * N
    y += dy
    x += dx
    if y >= N || y < 0 || x < 0 || x >= N || a[y][x] != 0
        x -= dx
        y -= dy
        m += 1
        dy, dx = MV[m % 4]
    else
        a[y][x] = c
        c += 1
    end
end

puts a.map{|r| r.map{|v| "%03d" % [v] } * ' ' } * "\n"
0