結果

問題 No.223 1マス指定の魔方陣
ユーザー maspymaspy
提出日時 2020-03-28 13:59:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 131 ms / 5,000 ms
コード長 1,275 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 11,020 KB
実行使用メモリ 29,868 KB
最終ジャッジ日時 2023-08-30 17:39:29
合計ジャッジ時間 10,108 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
29,636 KB
testcase_01 AC 122 ms
29,836 KB
testcase_02 AC 123 ms
29,708 KB
testcase_03 AC 124 ms
29,596 KB
testcase_04 AC 123 ms
29,780 KB
testcase_05 AC 124 ms
29,640 KB
testcase_06 AC 123 ms
29,680 KB
testcase_07 AC 123 ms
29,700 KB
testcase_08 AC 124 ms
29,776 KB
testcase_09 AC 123 ms
29,752 KB
testcase_10 AC 123 ms
29,760 KB
testcase_11 AC 124 ms
29,676 KB
testcase_12 AC 124 ms
29,704 KB
testcase_13 AC 124 ms
29,824 KB
testcase_14 AC 124 ms
29,648 KB
testcase_15 AC 127 ms
29,700 KB
testcase_16 AC 124 ms
29,680 KB
testcase_17 AC 122 ms
29,704 KB
testcase_18 AC 127 ms
29,688 KB
testcase_19 AC 122 ms
29,820 KB
testcase_20 AC 121 ms
29,760 KB
testcase_21 AC 122 ms
29,748 KB
testcase_22 AC 123 ms
29,700 KB
testcase_23 AC 124 ms
29,688 KB
testcase_24 AC 123 ms
29,780 KB
testcase_25 AC 124 ms
29,676 KB
testcase_26 AC 121 ms
29,636 KB
testcase_27 AC 127 ms
29,720 KB
testcase_28 AC 125 ms
29,676 KB
testcase_29 AC 124 ms
29,816 KB
testcase_30 AC 122 ms
29,724 KB
testcase_31 AC 123 ms
29,844 KB
testcase_32 AC 126 ms
29,692 KB
testcase_33 AC 124 ms
29,648 KB
testcase_34 AC 123 ms
29,716 KB
testcase_35 AC 124 ms
29,672 KB
testcase_36 AC 123 ms
29,724 KB
testcase_37 AC 123 ms
29,844 KB
testcase_38 AC 123 ms
29,864 KB
testcase_39 AC 122 ms
29,732 KB
testcase_40 AC 125 ms
29,732 KB
testcase_41 AC 130 ms
29,868 KB
testcase_42 AC 130 ms
29,676 KB
testcase_43 AC 131 ms
29,836 KB
testcase_44 AC 131 ms
29,724 KB
testcase_45 AC 130 ms
29,756 KB
testcase_46 AC 131 ms
29,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np


class Fq(int):
    deg = 2
    irr_poly = 7

    @classmethod
    def set_degree(cls, d):
        cls.deg = d
        cls.irr_poly = [1, 2, 7, 11, 19][d]

    @classmethod
    def iter_all(cls):
        return (Fq(i) for i in range(1 << cls.deg))

    def __add__(self, other):
        return Fq(self ^ other)

    def __mul__(self, other):
        ret = 0
        d = self.__class__.deg
        p = self.__class__.irr_poly
        for i in range(d):
            if (other >> i) & 1:
                ret ^= self << i
        for i in range(d - 2, -1, -1):
            if ret & (1 << d + i):
                ret ^= p << i
        return Fq(ret)


N, X, Y, Z = map(int, read().split())
X, Y = Y - 1, X - 1
Z -= 1

Fq.set_degree(N.bit_length() - 1)
nums = np.array(list(Fq.iter_all()), dtype=object)
latine_1, latine_2 = (nums[None, :, None] + nums[2:4][:, None, None] * nums[None, None, :]).astype(int)
latine_1 += (Z // N) - latine_1[X, Y]
latine_1 %= N
latine_2 += (Z % N) - latine_2[X, Y]
latine_2 %= N
magic_square = latine_1 * N + latine_2 + 1

print('\n'.join(' '.join(row) for row in magic_square.astype(str)))
0