結果

問題 No.1241 Eternal Tours
ユーザー 👑 hitonanodehitonanode
提出日時 2020-09-10 01:54:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,697 ms / 6,000 ms
コード長 2,129 bytes
コンパイル時間 209 ms
コンパイル使用メモリ 11,224 KB
実行使用メモリ 96,020 KB
最終ジャッジ日時 2023-08-22 17:27:27
合計ジャッジ時間 53,302 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
33,928 KB
testcase_01 AC 138 ms
33,832 KB
testcase_02 AC 1,914 ms
95,772 KB
testcase_03 AC 142 ms
33,592 KB
testcase_04 AC 139 ms
33,804 KB
testcase_05 AC 138 ms
33,720 KB
testcase_06 AC 137 ms
33,828 KB
testcase_07 AC 138 ms
33,824 KB
testcase_08 AC 141 ms
33,800 KB
testcase_09 AC 139 ms
33,744 KB
testcase_10 AC 139 ms
33,832 KB
testcase_11 AC 153 ms
33,808 KB
testcase_12 AC 138 ms
33,828 KB
testcase_13 AC 137 ms
33,800 KB
testcase_14 AC 1,195 ms
61,220 KB
testcase_15 AC 136 ms
33,824 KB
testcase_16 AC 373 ms
40,108 KB
testcase_17 AC 2,363 ms
95,672 KB
testcase_18 AC 2,236 ms
91,688 KB
testcase_19 AC 2,403 ms
87,700 KB
testcase_20 AC 146 ms
33,792 KB
testcase_21 AC 163 ms
34,152 KB
testcase_22 AC 2,268 ms
87,784 KB
testcase_23 AC 192 ms
34,456 KB
testcase_24 AC 138 ms
33,912 KB
testcase_25 AC 139 ms
33,836 KB
testcase_26 AC 139 ms
33,908 KB
testcase_27 AC 139 ms
33,908 KB
testcase_28 AC 2,268 ms
95,940 KB
testcase_29 AC 1,734 ms
95,852 KB
testcase_30 AC 1,847 ms
96,020 KB
testcase_31 AC 978 ms
65,040 KB
testcase_32 AC 2,294 ms
95,728 KB
testcase_33 AC 2,415 ms
87,716 KB
testcase_34 AC 2,384 ms
95,844 KB
testcase_35 AC 2,258 ms
95,792 KB
testcase_36 AC 139 ms
33,912 KB
testcase_37 AC 137 ms
33,688 KB
testcase_38 AC 2,569 ms
87,564 KB
testcase_39 AC 2,697 ms
87,816 KB
testcase_40 AC 2,558 ms
95,900 KB
testcase_41 AC 2,577 ms
95,836 KB
testcase_42 AC 2,583 ms
87,764 KB
testcase_43 AC 2,628 ms
95,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import numpy as np


class NTT():
    def __init__(self, D, MOD, root):
        self.md = MOD
        self.w = np.array([1], np.int64)
        self.iw = np.array([1], np.int64)

        while len(self.w) < 1 << (D - 1):
            dw = pow(root, (self.md - 1) // (len(self.w) * 4), self.md)
            dwinv = pow(dw, -1, self.md)
            self.w = np.r_[self.w, self.w * dw] % self.md
            self.iw = np.r_[self.iw, self.iw * dwinv] % self.md

    def ntt(self, mat):
        in_shape = mat.shape
        n = in_shape[-1]

        m = n // 2
        while m:
            mat = mat.reshape(-1, n // (m * 2), 2, m)
            w_use = self.w[:n // (m * 2)].reshape(1, -1, 1)
            y = mat[:, :, 1] * w_use % self.md
            mat = np.stack((mat[:, :, 0] + y, mat[:, :, 0] + self.md - y), 2) % self.md
            m //= 2
        return mat.reshape(in_shape)

    def intt(self, mat):
        in_shape = mat.shape
        n = in_shape[-1]

        m = 1
        while m < n:
            mat = mat.reshape(-1, n // (m * 2), 2, m)
            iw_use = self.iw[:n // (m * 2)].reshape(1, -1, 1)
            mat = np.stack((mat[:, :, 0] + mat[:, :, 1], (mat[:, :, 0] + self.md - mat[:, :, 1]) * iw_use), 2) % self.md
            m *= 2
        n_inv = pow(n, -1, self.md)
        return mat.reshape(in_shape) * n_inv % self.md


X, Y, T, a, b, c, d = list(map(int, input().split()))

md = 998244353
T = (T - 1) % (md - 1) + 1

H, W = 1 << (X + 1), 1 << (Y + 1)
dp = np.zeros((H, W), np.int64)
trans = np.zeros((H, W), np.int64)

dp[a, b] = dp[-a, -b] = 1
dp[a, -b] = dp[-a, b] = md - 1
trans[0, 0] = trans[0, 1] = trans[0, -1] = trans[1, 0] = trans[-1, 0] = 1

ntt = NTT(18, md, 3)

dp = ntt.ntt(dp)
trans = ntt.ntt(trans)

dp = dp.T
trans = trans.T

dp = ntt.ntt(dp)
trans = ntt.ntt(trans)

def matpow(x, n, mod):
    ret, tmp = np.ones(x.shape, np.int64), x % mod
    while n:
        if n % 2:
            ret = ret * tmp % mod
        tmp = tmp * tmp % mod
        n //= 2
    return ret

dp = dp * matpow(trans, T, md) % md

dp = ntt.intt(dp)
dp = dp.T
dp = ntt.intt(dp)

print(dp[c][d])
0