結果

問題 No.1241 Eternal Tours
ユーザー maspymaspy
提出日時 2020-09-26 10:53:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,193 ms / 6,000 ms
コード長 2,063 bytes
コンパイル時間 591 ms
コンパイル使用メモリ 11,076 KB
実行使用メモリ 87,200 KB
最終ジャッジ日時 2023-09-11 06:38:10
合計ジャッジ時間 44,550 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 186 ms
54,280 KB
testcase_01 AC 189 ms
54,244 KB
testcase_02 AC 1,239 ms
86,912 KB
testcase_03 AC 195 ms
54,276 KB
testcase_04 AC 193 ms
54,124 KB
testcase_05 AC 192 ms
54,132 KB
testcase_06 AC 191 ms
54,120 KB
testcase_07 AC 191 ms
53,744 KB
testcase_08 AC 193 ms
53,940 KB
testcase_09 AC 191 ms
54,148 KB
testcase_10 AC 191 ms
54,236 KB
testcase_11 AC 192 ms
54,092 KB
testcase_12 AC 189 ms
54,136 KB
testcase_13 AC 190 ms
54,056 KB
testcase_14 AC 955 ms
66,564 KB
testcase_15 AC 190 ms
54,272 KB
testcase_16 AC 358 ms
54,148 KB
testcase_17 AC 1,899 ms
86,772 KB
testcase_18 AC 1,811 ms
87,064 KB
testcase_19 AC 1,926 ms
86,916 KB
testcase_20 AC 199 ms
54,164 KB
testcase_21 AC 215 ms
54,348 KB
testcase_22 AC 1,866 ms
87,072 KB
testcase_23 AC 237 ms
54,100 KB
testcase_24 AC 197 ms
54,324 KB
testcase_25 AC 196 ms
54,136 KB
testcase_26 AC 196 ms
54,152 KB
testcase_27 AC 196 ms
54,128 KB
testcase_28 AC 1,199 ms
78,724 KB
testcase_29 AC 1,196 ms
78,756 KB
testcase_30 AC 1,336 ms
86,892 KB
testcase_31 AC 729 ms
66,224 KB
testcase_32 AC 1,829 ms
86,932 KB
testcase_33 AC 1,890 ms
87,104 KB
testcase_34 AC 1,904 ms
87,144 KB
testcase_35 AC 1,769 ms
87,200 KB
testcase_36 AC 194 ms
54,108 KB
testcase_37 AC 192 ms
54,092 KB
testcase_38 AC 2,061 ms
86,796 KB
testcase_39 AC 2,058 ms
86,784 KB
testcase_40 AC 2,068 ms
86,768 KB
testcase_41 AC 2,104 ms
86,748 KB
testcase_42 AC 2,193 ms
86,884 KB
testcase_43 AC 2,175 ms
86,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 998_244_353

def ntt_precompute(N, primitive_root):
    roots = np.empty(1 << N, np.int64)
    iroots = np.empty(1 << N, np.int64)
    roots[0] = iroots[0] = 1
    for n in range(N):
        x = pow(primitive_root, (MOD - 1) >> n + 2, MOD)
        y = pow(x, -1, MOD)
        roots[1 << n:1 << n + 1] = roots[:1 << n] * x % MOD
        iroots[1 << n:1 << n + 1] = iroots[:1 << n] * y % MOD
    return roots, iroots


def ntt(roots, iroots, A, inverse):
    """along first axis"""
    shape = A.shape
    N = len(A)
    if not inverse:
        m = N >> 1
        while m:
            A = A.reshape((-1, m) + shape[1:])
            x, y = A[::2], A[1::2] * roots[:N // m >> 1].reshape(
                (-1, ) + (1, ) * len(shape))
            A[::2], A[1::2] = x + y, x - y
            A %= MOD
            m >>= 1
    else:
        m = 1
        while m < N:
            A = A.reshape((-1, m) + shape[1:])
            x, y = A[::2], A[1::2]
            A[::2], A[1::2] = x + y, (x - y) * iroots[:N // m >> 1].reshape(
                (-1, ) + (1, ) * len(shape))
            A %= MOD
            m <<= 1
        invN = pow(N, -1, MOD)
        A = A * invN % MOD
    return A.reshape(shape)

def mpow(A, n):
    n %= (MOD - 1)
    B = np.ones_like(A)
    while n:
        if n & 1:
            B = A * B % MOD
        A = A * A % MOD
        n >>= 1
    return B

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

# Z/2^(X+1)Z x Z/2^(Y+1)Z での遷移
H, W = 1 << (X + 1), 1 << (Y + 1)
f = np.zeros((H, W), np.int64)
f[0, 0] = f[1, 0] = f[0, 1] = f[-1, 0] = f[0, -1] = 1

# T 乗する
roots, iroots = ntt_precompute(20, 3)
Ff = ntt(roots, iroots, f, False)
Ff = ntt(roots, iroots, Ff.T, False).T
Ff = mpow(Ff, T)
Ff = ntt(roots, iroots, Ff.T, True).T
f = ntt(roots, iroots, Ff, True)

ans = 0
ans += f[c - a, d - b]
ans -= f[c - H + a, d - b]
ans -= f[c - a, d - W + b]
ans += f[c - H + a, d - W + b]
ans %= MOD
print(ans)
0