結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
tsuchinaga
|
| 提出日時 | 2019-02-26 00:31:52 |
| 言語 | Go (1.23.4) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 548 bytes |
| コンパイル時間 | 12,182 ms |
| コンパイル使用メモリ | 220,440 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-30 09:52:20 |
| 合計ジャッジ時間 | 12,570 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
package main
import (
"fmt"
"strings"
)
func main() {
var n int
_, _ = fmt.Scan(&n)
s, l, d, x, y := 1, n, 1, -1, 0
nums := make([]int, n*n)
for i := 0; i < 2*n-1; i++ {
for j := 0; j < l; j++ {
switch d {
case 0:
y--
case 1:
x++
case 2:
y++
case 3:
x--
}
nums[x+y*n] = s
s++
}
d = (d + 1) % 4
if i%2 == 0 {
l--
}
}
for y := 0; y < n; y++ {
line := ""
for x := 0; x < n; x++ {
line += fmt.Sprintf("%03d ", nums[x+y*n])
}
fmt.Printf("%s\n", strings.Trim(line, " "))
}
}
tsuchinaga