結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-23 16:24:25 |
| 言語 | Nim (2.2.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 749 bytes |
| コンパイル時間 | 3,990 ms |
| コンパイル使用メモリ | 67,040 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-19 04:27:00 |
| 合計ジャッジ時間 | 3,682 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
import sequtils, strutils
proc printf(str: cstring) {.header: "<stdio.h>", importc: "printf", varargs.}
let n: int = stdin.readline.parseInt
var
a: seq[seq[int]] = newSeqWith(n, newSeq[int](n))
b: seq[seq[bool]] = newSeqWith(n, newSeq[bool](n))
x, y, tx, ty, cnt: int
dx: array[4, int] = [1, 0, -1, 0]
dy: array[4, int] = [0, 1, 0, -1]
a[x][y] = 1
b[x][y] = true
for i in 1..<(n * n):
tx = x + dx[cnt and 3]
ty = y + dy[cnt and 3]
if tx < 0 or tx >= n or ty < 0 or ty >= n or b[tx][ty]:
cnt.inc
tx = x + dx[cnt and 3]
ty = y + dy[cnt and 3]
x = tx
y = ty
a[x][y] = i + 1
b[x][y] = true
for j in 0..<n:
for i in 0..<n:
printf("%03d", a[i][j])
if i == n - 1:
printf("\n")
else:
printf(" ")