結果

問題 No.217 魔方陣を作ろう
ユーザー vwxyzvwxyz
提出日時 2023-07-14 12:17:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 36 ms / 5,000 ms
コード長 2,049 bytes
コンパイル時間 1,064 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 10,636 KB
最終ジャッジ日時 2023-10-14 01:44:25
合計ジャッジ時間 2,130 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
10,636 KB
testcase_01 AC 35 ms
10,408 KB
testcase_02 AC 34 ms
10,528 KB
testcase_03 AC 36 ms
10,408 KB
testcase_04 AC 35 ms
10,520 KB
testcase_05 AC 34 ms
10,508 KB
testcase_06 AC 34 ms
10,500 KB
testcase_07 AC 36 ms
10,508 KB
testcase_08 AC 35 ms
10,448 KB
testcase_09 AC 34 ms
10,480 KB
testcase_10 AC 34 ms
10,476 KB
testcase_11 AC 34 ms
10,508 KB
testcase_12 AC 34 ms
10,520 KB
testcase_13 AC 34 ms
10,544 KB
testcase_14 AC 33 ms
10,416 KB
testcase_15 AC 35 ms
10,524 KB
testcase_16 AC 34 ms
10,432 KB
testcase_17 AC 34 ms
10,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import copy
import decimal
import fractions
import heapq
import itertools
import math
import random
import sys
import time
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush_max(heap,item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappushpop_max(heap, item):
    if heap and item < heap[0]:
        item, heap[0] = heap[0], item
        heapq._siftup_max(heap, 0)
    return item
from math import gcd as GCD
read=sys.stdin.read
readline=sys.stdin.readline
readlines=sys.stdin.readlines
write=sys.stdout.write

def Magic_Circle(N):
    if N==2:
        magic_cycle=None
    elif N%4==0:
        magic_cycle=[[None]*N for x in range(N)]
        for x in range(N):
            for y in range(N):
                if (x-y)%4==0 or (x+y)%4==3:
                    magic_cycle[x][y]=x*N+y
        for x in range(N-1,-1,-1):
            for y in range(N-1,-1,-1):
                if magic_cycle[x][y]==None:
                    magic_cycle[x][y]=(N-1-x)*N+(N-1-y)
    elif N%4==2:
        n=N//2
        magic_cycle=[[None]*N for x in range(N)]
        mc=Magic_Circle(n)
        L=[[3,0],[1,2]]
        U=[[0,3],[1,2]]
        X=[[0,3],[2,1]]
        for x in range(n):
            for y in range(n):
                if n//2+1<x:
                    LUX=X
                elif x==n//2+1 and y!=n//2 or (x,y)==(n//2,n//2):
                    LUX=U
                else:
                    LUX=L
                for i in range(2):
                    for j in range(2):
                        magic_cycle[x*2+i][y*2+j]=mc[x][y]*4+LUX[i][j]
    else:
        n=N//2
        magic_cycle=[[None]*N for i in range(N)]
        for i in range(N):
            for j in range(N):
                magic_cycle[(i+j-n)%N][(-i+j+n)%N]=i*N+j
    return magic_cycle

N=int(readline())
A=Magic_Circle(N)
for i in range(N):
    for j in range(N):
        A[i][j]+=1
for a in A:
    print(*a)
0