結果

問題 No.223 1マス指定の魔方陣
ユーザー keikei
提出日時 2018-09-24 16:49:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 520 ms / 5,000 ms
コード長 3,494 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 44,856 KB
最終ジャッジ日時 2024-09-22 06:54:49
合計ジャッジ時間 26,615 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 504 ms
44,648 KB
testcase_01 AC 507 ms
44,720 KB
testcase_02 AC 507 ms
44,728 KB
testcase_03 AC 502 ms
44,848 KB
testcase_04 AC 499 ms
44,600 KB
testcase_05 AC 505 ms
44,336 KB
testcase_06 AC 520 ms
44,596 KB
testcase_07 AC 507 ms
44,208 KB
testcase_08 AC 504 ms
44,464 KB
testcase_09 AC 507 ms
44,336 KB
testcase_10 AC 505 ms
44,856 KB
testcase_11 AC 501 ms
44,216 KB
testcase_12 AC 507 ms
44,848 KB
testcase_13 AC 507 ms
44,848 KB
testcase_14 AC 508 ms
44,724 KB
testcase_15 AC 506 ms
44,464 KB
testcase_16 AC 507 ms
44,592 KB
testcase_17 AC 501 ms
44,340 KB
testcase_18 AC 507 ms
44,604 KB
testcase_19 AC 502 ms
44,208 KB
testcase_20 AC 508 ms
44,460 KB
testcase_21 AC 506 ms
44,336 KB
testcase_22 AC 502 ms
44,472 KB
testcase_23 AC 506 ms
44,204 KB
testcase_24 AC 508 ms
44,848 KB
testcase_25 AC 513 ms
44,340 KB
testcase_26 AC 500 ms
44,460 KB
testcase_27 AC 501 ms
44,336 KB
testcase_28 AC 504 ms
44,616 KB
testcase_29 AC 507 ms
44,336 KB
testcase_30 AC 502 ms
44,592 KB
testcase_31 AC 504 ms
44,340 KB
testcase_32 AC 505 ms
44,336 KB
testcase_33 AC 505 ms
44,588 KB
testcase_34 AC 504 ms
44,336 KB
testcase_35 AC 512 ms
44,592 KB
testcase_36 AC 502 ms
44,340 KB
testcase_37 AC 510 ms
44,680 KB
testcase_38 AC 505 ms
44,592 KB
testcase_39 AC 507 ms
44,204 KB
testcase_40 AC 509 ms
44,464 KB
testcase_41 AC 506 ms
44,592 KB
testcase_42 AC 509 ms
44,856 KB
testcase_43 AC 510 ms
44,724 KB
testcase_44 AC 507 ms
44,344 KB
testcase_45 AC 501 ms
44,848 KB
testcase_46 AC 503 ms
44,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

'''
    <url:https://yukicoder.me/problems/no/223>
    問題文============================================================
    =================================================================
    解説=============================================================
    
    完全方陣探して来て、ずらせばいい。
    
    ここに4x4 8x8 16x16がある
    >> https://www.magischvierkant.com/two-dimensional-eng/most-perfect-magic/
    ================================================================
    '''
import numpy as np
n,x,y,z = input().strip().split(' ')
n,x,y,z =[int(n),int(x),int(y),int(z)]
x-=1
y-=1
if n == 4:
    ans = np.array([
                    [1,14,4,15],
                    [8,11,5,10],
                    [13,2,16,3],
                    [12,7,9,6],
                    ])
elif n == 8:
    ans = np.array([[ 1, 16, 57, 56, 33, 48, 25, 24],
                 [63, 50,  7, 10, 31, 18, 39, 42],
                 [ 8,  9, 64, 49, 40, 41, 32, 17],
                 [58, 55,  2, 15, 26, 23, 34, 47],
                 [ 5, 12, 61, 52, 37, 44, 29, 20],
                 [59, 54,  3, 14, 27, 22, 35, 46],
                 [ 4, 13, 60, 53, 36, 45, 28, 21],
                 [62, 51,  6, 11, 30, 19, 38, 43]])
else:
    ans = np.array([[  1, 248,  61, 204,  49, 200,  13, 252,  17, 232,  45, 220,  33,
                     216,  29, 236],
                    [255,  10, 195,  54, 207,  58, 243,   6, 239,  26, 211,  38, 223,
                     42, 227,  22],
                    [196,  53, 256,   9, 244,   5, 208,  57, 212,  37, 240,  25, 228,
                     21, 224,  41],
                    [ 62, 203,   2, 247,  14, 251,  50, 199,  46, 219,  18, 231,  30,
                     235,  34, 215],
                    [193,  56, 253,  12, 241,   8, 205,  60, 209,  40, 237,  28, 225,
                     24, 221,  44],
                    [ 63, 202,   3, 246,  15, 250,  51, 198,  47, 218,  19, 230,  31,
                     234,  35, 214],
                    [  4, 245,  64, 201,  52, 197,  16, 249,  20, 229,  48, 217,  36,
                     213,  32, 233],
                    [254,  11, 194,  55, 206,  59, 242,   7, 238,  27, 210,  39, 222,
                     43, 226,  23],
                    [ 65, 184, 125, 140, 113, 136,  77, 188,  81, 168, 109, 156,  97,
                     152,  93, 172],
                    [191,  74, 131, 118, 143, 122, 179,  70, 175,  90, 147, 102, 159,
                     106, 163,  86],
                    [132, 117, 192,  73, 180,  69, 144, 121, 148, 101, 176,  89, 164,
                     85, 160, 105],
                    [126, 139,  66, 183,  78, 187, 114, 135, 110, 155,  82, 167,  94,
                     171,  98, 151],
                    [129, 120, 189,  76, 177,  72, 141, 124, 145, 104, 173,  92, 161,
                     88, 157, 108],
                    [127, 138,  67, 182,  79, 186, 115, 134, 111, 154,  83, 166,  95,
                     170,  99, 150],
                    [ 68, 181, 128, 137, 116, 133,  80, 185,  84, 165, 112, 153, 100,
                     149,  96, 169],
                    [190,  75, 130, 119, 142, 123, 178,  71, 174,  91, 146, 103, 158,
                     107, 162,  87]])

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)
ans = ans[kx:kx+n,ky:ky+n]

#print(ans)
for i in range(n):
    for j in range(n):
        print(ans[i][j],end=" ")
    print("")
0