結果
問題 |
No.223 1マス指定の魔方陣
|
ユーザー |
![]() |
提出日時 | 2025-06-12 18:52:12 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,746 bytes |
コンパイル時間 | 300 ms |
コンパイル使用メモリ | 82,156 KB |
実行使用メモリ | 68,228 KB |
最終ジャッジ日時 | 2025-06-12 18:52:27 |
合計ジャッジ時間 | 4,892 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 21 RE * 25 |
ソースコード
N, X, Y, Z = map(int, input().split()) X -= 1 # Convert to 0-based index Y -= 1 def make_doubly_even_magic_square(n): mat = [[i * n + j + 1 for j in range(n)] for i in range(n)] for i in range(n): for j in range(n): sub_i = i % 4 sub_j = j % 4 if (sub_i in (0, 3) and sub_j in (0, 3)) or (sub_i in (1, 2) and sub_j in (1, 2)): mat[i][j] = (n * n + 1) - mat[i][j] return mat def rotate(matrix): n = len(matrix) return [[matrix[n - j - 1][i] for j in range(n)] for i in range(n)] def reflect_horizontal(matrix): return [row[::-1] for row in matrix] def reflect_vertical(matrix): return [row for row in reversed(matrix)] def generate_transformations(matrix): transforms = [] current = matrix for _ in range(4): transforms.append(current) transforms.append(reflect_horizontal(current)) transforms.append(reflect_vertical(current)) current = rotate(current) return transforms # Generate the magic square using the doubly even method magic_square = make_doubly_even_magic_square(N) # Check all transformations of the generated magic square found = None for variant in generate_transformations(magic_square): if variant[Y][X] == Z: found = variant break # If not found, check a known magic square for N=4 (as a fallback) if not found and N == 4: known_square = [ [3, 13, 16, 2], [10, 8, 5, 11], [6, 12, 9, 7], [15, 1, 4, 14] ] for variant in generate_transformations(known_square): if variant[Y][X] == Z: found = variant break # Output the found magic square for row in found: print(' '.join(map(str, row)))