結果
問題 | No.217 魔方陣を作ろう |
ユーザー | rpy3cpp |
提出日時 | 2015-05-26 23:44:16 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,716 bytes |
コンパイル時間 | 381 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-07-06 10:30:18 |
合計ジャッジ時間 | 1,515 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 24 ms
10,880 KB |
testcase_01 | AC | 25 ms
10,880 KB |
testcase_02 | AC | 25 ms
10,880 KB |
testcase_03 | AC | 25 ms
10,880 KB |
testcase_04 | AC | 24 ms
11,008 KB |
testcase_05 | AC | 24 ms
10,880 KB |
testcase_06 | AC | 24 ms
10,880 KB |
testcase_07 | WA | - |
testcase_08 | AC | 24 ms
10,880 KB |
testcase_09 | AC | 24 ms
10,880 KB |
testcase_10 | AC | 24 ms
11,008 KB |
testcase_11 | WA | - |
testcase_12 | AC | 23 ms
11,008 KB |
testcase_13 | AC | 24 ms
11,008 KB |
testcase_14 | AC | 24 ms
10,880 KB |
testcase_15 | WA | - |
testcase_16 | AC | 24 ms
10,880 KB |
testcase_17 | AC | 24 ms
10,880 KB |
ソースコード
def solve(): N = int(input()) if N & 1: magic = solve_odd(N) elif N % 4 == 0: magic = solve_4(N) else: magic = solve_LUX(N) print_mat(magic) def print_mat(magic): for row in magic: print(' '.join(map(str,row))) def solve_odd(N): magic = [[0] * N for i in range(N)] mid = N // 2 num = 1 x = 0 y = mid while num <= N * N: while magic[x][y]: x = (x + 2) % N y = (y - 1) % N magic[x][y] = num num += 1 x = (x - 1) % N y = (y + 1) % N return magic def solve_4(N): magic = [[0] * N for i in range(N)] num = 1 for x in range(N): for y in range(N): if is_diagonal(x, y): magic[x][y] = num num += 1 num = 1 for x in range(N-1, -1, -1): for y in range(N-1, -1, -1): if not magic[x][y]: magic[x][y] = num num += 1 return magic def is_diagonal(x, y): x %= 4 y %= 4 return x == y or x + y == 3 def solve_LUX(N): seed = solve_odd(N//2) LUX = [[0] * (N//2) for i in range(1 + N//4)] LUX.extend([[1] * (N//2) for i in range(N//4)]) LUX.append([2] * (N//2)) LUX[N//4][N//4] = 1 LUX[1 + N//4][N//4] = 0 L = [[4, 1], [2, 3]] U = [[1, 4], [2, 3]] X = [[1, 4], [3, 2]] LUXmat = [L, U, X] magic = [[0] * N for i in range(N)] for x in range(N//2): for y in range(N//2): val = (seed[x][y] - 1) * 4 idx = LUX[x][y] for dx, dy in [(0, 0), (0, 1), (1, 0), (1, 1)]: magic[2 * x + dx][2 * y + dy] = LUXmat[idx][dx][dy] + val return magic solve()