結果

問題 No.217 魔方陣を作ろう
ユーザー fmhrfmhr
提出日時 2015-05-27 00:25:25
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 769 bytes
コンパイル時間 12,039 ms
コンパイル使用メモリ 224,188 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 02:06:54
合計ジャッジ時間 11,198 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 1 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 1 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 1 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 1 ms
5,376 KB
testcase_09 WA -
testcase_10 AC 1 ms
5,376 KB
testcase_11 WA -
testcase_12 AC 2 ms
5,376 KB
testcase_13 WA -
testcase_14 AC 1 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 2 ms
5,376 KB
testcase_17 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	z := make([][]int, N)
	for i := 0; i < N; i++ {
		z[i] = make([]int, N)
	}
	if N%2 == 1 {
		row := 0
		col := N / 2
		for i := 0; i < N*N; i++ {
			z[row][col] = i + 1
			nrow := (row + N - 1) % N
			ncol := (col + 1) % N
			if z[nrow][ncol] != 0 {
				nrow = (row + 1) % N
				ncol = col
			}
			row = nrow
			col = ncol

		}
	} else {
		var row, col int
		row = N - 1
		col = N / 2
		z[row][col] = 1
		for i := 2; i <= N*N; i++ {
			if z[(row+1)%N][(col+1)%N] == 0 {
				row = (row + 1) % N
				col = (col + 1) % N
			} else {
				row = (row - 1 + N) % N
			}
			z[row][col] = i
		}
	}
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			fmt.Print(z[i][j], " ")
		}
		fmt.Println("")
	}
}

0