結果

問題 No.401 数字の渦巻き
ユーザー maimai
提出日時 2016-07-22 23:17:23
言語 Ruby
(3.3.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 474 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 11,452 KB
実行使用メモリ 15,376 KB
最終ジャッジ日時 2023-08-27 01:41:48
合計ジャッジ時間 4,315 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
15,184 KB
testcase_01 AC 82 ms
15,180 KB
testcase_02 AC 81 ms
15,064 KB
testcase_03 AC 82 ms
15,236 KB
testcase_04 AC 87 ms
15,128 KB
testcase_05 AC 75 ms
15,288 KB
testcase_06 AC 80 ms
15,264 KB
testcase_07 AC 74 ms
15,320 KB
testcase_08 AC 83 ms
15,308 KB
testcase_09 AC 82 ms
15,152 KB
testcase_10 AC 82 ms
15,180 KB
testcase_11 AC 83 ms
15,088 KB
testcase_12 AC 83 ms
15,252 KB
testcase_13 AC 83 ms
15,188 KB
testcase_14 AC 83 ms
15,272 KB
testcase_15 AC 77 ms
15,244 KB
testcase_16 AC 84 ms
15,280 KB
testcase_17 AC 77 ms
15,272 KB
testcase_18 AC 84 ms
15,220 KB
testcase_19 AC 84 ms
15,148 KB
testcase_20 AC 85 ms
15,252 KB
testcase_21 AC 88 ms
15,376 KB
testcase_22 AC 87 ms
15,280 KB
testcase_23 AC 86 ms
15,248 KB
testcase_24 AC 85 ms
15,252 KB
testcase_25 AC 84 ms
15,196 KB
testcase_26 AC 84 ms
15,204 KB
testcase_27 AC 77 ms
15,164 KB
testcase_28 AC 85 ms
15,224 KB
testcase_29 AC 84 ms
15,204 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n=gets.to_i

if n==1
    puts "001";exit
end

a=Array.new(n){Array.new(n)}

def right(vx,vy)
    return [0,1] if vx==1
    return [-1,0] if vy==1
    return [0,-1] if vx==-1
    return [1,0]
end

x=0;y=0;vx=1;vy=0;count=1

while (!a[y][x])
    a[y][x]=count
    count+=1
    
    x+=vx;y+=vy
    
    if x<0||y<0||n<=x||n<=y||a[y][x]!=nil
        x-=vx;y-=vy
        vx,vy=right(vx,vy)
        x+=vx;y+=vy
    end
    
end

a.each{|e| puts e.map{|f| sprintf("%03d",f)}*" " }
0