結果

問題 No.401 数字の渦巻き
ユーザー MaboyMaboy
提出日時 2021-06-21 11:15:36
言語 Swift
(5.10.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 663 bytes
コンパイル時間 4,984 ms
コンパイル使用メモリ 174,072 KB
実行使用メモリ 13,868 KB
最終ジャッジ日時 2023-09-05 01:49:29
合計ジャッジ時間 6,978 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
13,696 KB
testcase_01 AC 6 ms
13,464 KB
testcase_02 AC 6 ms
13,604 KB
testcase_03 AC 6 ms
13,788 KB
testcase_04 AC 6 ms
13,552 KB
testcase_05 AC 6 ms
13,264 KB
testcase_06 AC 6 ms
13,788 KB
testcase_07 AC 6 ms
13,604 KB
testcase_08 AC 6 ms
13,692 KB
testcase_09 AC 6 ms
13,504 KB
testcase_10 AC 6 ms
13,552 KB
testcase_11 AC 6 ms
13,264 KB
testcase_12 AC 6 ms
13,556 KB
testcase_13 AC 6 ms
13,368 KB
testcase_14 AC 6 ms
13,776 KB
testcase_15 AC 7 ms
13,696 KB
testcase_16 AC 7 ms
13,468 KB
testcase_17 AC 7 ms
13,608 KB
testcase_18 AC 7 ms
13,536 KB
testcase_19 AC 7 ms
13,372 KB
testcase_20 AC 7 ms
13,696 KB
testcase_21 AC 7 ms
13,556 KB
testcase_22 AC 7 ms
13,668 KB
testcase_23 AC 7 ms
13,556 KB
testcase_24 AC 8 ms
13,868 KB
testcase_25 AC 7 ms
13,696 KB
testcase_26 AC 7 ms
13,508 KB
testcase_27 AC 8 ms
13,376 KB
testcase_28 AC 7 ms
13,484 KB
testcase_29 AC 8 ms
13,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import Foundation

let n = Int(readLine()!)!
var (y,x,cnt,dir) = (1,1,1,0)
let RDLU = [[0,1],[1,0],[0,-1],[-1,0]]

var map = [[Int]]() //空のmapを用意
for _ in 0...n + 1{
    map += [(Array<Int>)(repeating: -1, count: n + 2)]
}

for Y in 1...n{ //壁法で使うので真ん中を0にする
    for X in 1...n{
        map[Y][X] = 0
    }
}

while cnt <= n * n{
    map[y][x] = cnt
    cnt += 1
    if map[y + RDLU[dir][0]][x + RDLU[dir][1]] != 0{
        dir += dir < 3 ? 1 : -3
    }
    (y,x) = (y + RDLU[dir][0],x + RDLU[dir][1])
}


for Y in 1...n{
    for X in 1...n{
        print(String(format: "%03d", map[Y][X]),terminator: " ")
    }
    print()
}
0