結果
| 問題 | 
                            No.1241 Eternal Tours
                             | 
                    
| コンテスト | |
| ユーザー | 
                             maspy
                         | 
                    
| 提出日時 | 2020-09-26 10:53:16 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2,175 ms / 6,000 ms | 
| コード長 | 2,063 bytes | 
| コンパイル時間 | 84 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 101,524 KB | 
| 最終ジャッジ日時 | 2024-06-28 20:49:30 | 
| 合計ジャッジ時間 | 51,068 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 40 | 
ソースコード
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)
            
            
            
        
            
maspy