結果

問題 No.223 1マス指定の魔方陣
ユーザー keikei
提出日時 2018-09-24 16:11:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,525 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 12,192 KB
実行使用メモリ 42,704 KB
最終ジャッジ日時 2023-10-22 03:49:44
合計ジャッジ時間 25,553 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 419 ms
42,704 KB
testcase_01 AC 429 ms
42,704 KB
testcase_02 AC 418 ms
42,704 KB
testcase_03 AC 422 ms
42,704 KB
testcase_04 AC 423 ms
42,704 KB
testcase_05 AC 416 ms
42,704 KB
testcase_06 AC 412 ms
42,704 KB
testcase_07 AC 410 ms
42,704 KB
testcase_08 AC 413 ms
42,704 KB
testcase_09 AC 418 ms
42,704 KB
testcase_10 AC 420 ms
42,704 KB
testcase_11 AC 415 ms
42,704 KB
testcase_12 AC 412 ms
42,704 KB
testcase_13 AC 421 ms
42,704 KB
testcase_14 AC 409 ms
42,704 KB
testcase_15 AC 419 ms
42,704 KB
testcase_16 AC 418 ms
42,704 KB
testcase_17 AC 425 ms
42,704 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 429 ms
42,704 KB
testcase_21 AC 434 ms
42,704 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 415 ms
42,704 KB
testcase_29 AC 413 ms
42,704 KB
testcase_30 AC 422 ms
42,704 KB
testcase_31 AC 418 ms
42,704 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 411 ms
42,704 KB
testcase_35 AC 425 ms
42,704 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 414 ms
42,704 KB
testcase_39 AC 438 ms
42,704 KB
testcase_40 AC 415 ms
42,704 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 411 ms
42,704 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

'''
    <url:https://yukicoder.me/problems/no/217>
    問題文============================================================
    =================================================================
    解説=============================================================
    
    参考サイトや既存の魔法陣のテンプレ貼り付けてほい
    ================================================================
'''
import numpy as np
def magic(n):
    n = int(n)
    if n % 2 == 1:
        p = np.arange(1, n+1)
        return n*np.mod(p[:, None] + p - (n+3)//2, n) + np.mod(p[:, None] + 2*p-2, n) + 1
    elif n % 4 == 0:
        J = np.mod(np.arange(1, n+1), 4) // 2
        K = J[:, None] == J
        M = np.arange(1, n*n+1, n)[:, None] + np.arange(n)
        M[K] = n*n + 1 - M[K]
    else:
        p = n//2
        M = magic(p)
        M = np.block([[M, M+2*p*p], [M+3*p*p, M+p*p]])
        i = np.arange(p)
        k = (n-2)//4
        j = np.concatenate((np.arange(k), np.arange(n-k+1, n)))
        M[np.ix_(np.concatenate((i, i+p)), j)] = M[np.ix_(np.concatenate((i+p, i)), j)]
        M[np.ix_([k, k+p], [0, k])] = M[np.ix_([k+p, k], [0, k])]
    return M

n,x,y,z = input().strip().split(' ')
n,x,y,z =[int(n),int(x),int(y),int(z)]
x-=1
y-=1
ans = magic(n)

kx,ky = np.where(ans==z)
kx = int(kx)
ky = int(ky)
kx += n - y
ky += n - x
ans = np.concatenate([ans,ans,ans])
ans = np.concatenate([ans,ans,ans],axis=1)
for i in range(n):
    for j in range(n):
        print(ans[i+kx][j+ky],end=" ")
    print("")
0