結果

問題 No.2013 Can we meet?
ユーザー 👑 rin204rin204
提出日時 2022-07-15 23:21:58
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 4,099 bytes
コンパイル時間 1,438 ms
コンパイル使用メモリ 86,884 KB
実行使用メモリ 114,760 KB
最終ジャッジ日時 2023-09-10 05:13:11
合計ジャッジ時間 12,297 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
79,200 KB
testcase_01 AC 84 ms
79,472 KB
testcase_02 AC 84 ms
79,048 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 84 ms
79,196 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 83 ms
79,180 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 85 ms
79,404 KB
testcase_13 WA -
testcase_14 AC 85 ms
79,616 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 85 ms
79,616 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 103 ms
94,384 KB
testcase_33 AC 681 ms
113,504 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 468 ms
113,212 KB
testcase_38 AC 100 ms
94,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 自分用メモ

MOD = 998244353
N = 200200
fact = [0 for _ in range(N)]
invfact = [0 for _ in range(N)]
fact[0] = 1
for i in range(1, N):
    fact[i] = fact[i - 1] * i % MOD

invfact[N - 1] = pow(fact[N - 1], MOD - 2, MOD)

for i in range(N - 2, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % MOD

def nCk(n, k):
    if k < 0 or n < k:
        return 0
    else:
        return (fact[n] * invfact[k] % MOD) * invfact[n - k] % MOD

def nPk(n, k):
    if k < 0 or n < k:
        return 0
    else:
        return fact[n] * invfact[n - k] % MOD

def nHk(n, k):
    if n == k == 0:
        return 1
    return nCk(n + k - 1, k)

class FFT:
    def __init__(self, MOD=998244353):
        FFT.MOD = MOD
        g = self.primitive_root_constexpr()
        ig = pow(g, FFT.MOD - 2, FFT.MOD)
        FFT.W = [pow(g, (FFT.MOD - 1) >> i, FFT.MOD) for i in range(30)]
        FFT.iW = [pow(ig, (FFT.MOD - 1) >> i, FFT.MOD) for i in range(30)]

    def primitive_root_constexpr(self):
        if FFT.MOD == 998244353:
            return 3
        elif FFT.MOD == 200003:
            return 2
        elif FFT.MOD == 167772161:
            return 3
        elif FFT.MOD == 469762049:
            return 3
        elif FFT.MOD == 754974721:
            return 11
        divs = [0] * 20
        divs[0] = 2
        cnt = 1
        x = (FFT.MOD - 1) // 2
        while x % 2 == 0:
            x //= 2
        i = 3
        while i * i <= x:
            if x % i == 0:
                divs[cnt] = i
                cnt += 1
                while x % i == 0:
                    x //= i
            i += 2
        if x > 1:
            divs[cnt] = x
            cnt += 1
        g = 2
        while 1:
            ok = True
            for i in range(cnt):
                if pow(g, (FFT.MOD - 1) // divs[i], FFT.MOD) == 1:
                    ok = False
                    break
            if ok:
                return g
            g += 1

    def fft(self, k, f):
        for l in range(k, 0, -1):
            d = 1 << l - 1
            U = [1]
            for i in range(d):
                U.append(U[-1] * FFT.W[l] % FFT.MOD)
            
            for i in range(1 << k - l):
                for j in range(d):
                    s = i * 2 * d + j
                    f[s], f[s + d] = (f[s] + f[s + d]) % FFT.MOD, U[j] * (f[s] - f[s + d]) % FFT.MOD

    def ifft(self, k, f):
        for l in range(1, k + 1):
            d = 1 << l - 1
            for i in range(1 << k - l):
                u = 1
                for j in range(i * 2 * d, (i * 2 + 1) * d):
                    f[j+d] *= u
                    f[j], f[j + d] = (f[j] + f[j + d]) % FFT.MOD, (f[j] - f[j + d]) % FFT.MOD
                    u = u * FFT.iW[l] % FFT.MOD

    def convolve(self, A, B):
        n0 = len(A) + len(B) - 1
        k = (n0).bit_length()
        n = 1 << k
        A += [0] * (n - len(A))
        B += [0] * (n - len(B))
        self.fft(k, A)
        self.fft(k, B)
        A = [a * b % FFT.MOD for a, b in zip(A, B)]
        self.ifft(k, A)
        inv = pow(n, FFT.MOD - 2, FFT.MOD)
        A = [a * inv % FFT.MOD for a in A]
        del A[n0:]
        return A



n = int(input())
x1, y1, x2, y2 = map(int, input().split())
a, b = map(int, input().split())
A = list(map(int, input().split()))

dx = x2 - x1
dy = y2 - y1
if (dx + dy) & 1:
    print(0)
    exit()

lst = []
x = a * pow(2 * (a + b), MOD - 2, MOD) % MOD
y = a * pow(2 * (a + b), MOD - 2, MOD) % MOD
same = [0]
for t in range(2, 2 * n + 1, 2):
    ii = (dx + dy + t) // 2
    jj = ii - dx
    tmp = nCk(t, ii) * nCk(t, jj) % MOD
    xx = pow(x, ii, MOD)
    yy = pow(y, jj, MOD)
    times = xx * yy % MOD
    lst.append(tmp * times % MOD)

    # ここカタラン数っぽくしなきゃいけない
    ii = t // 2
    jj = ii
    tmp = nCk(t, ii) * nCk(t, jj) % MOD
    xx = pow(x, ii, MOD)
    yy = pow(y, jj, MOD)
    times = xx * yy % MOD
    tmp *= times
    same.append(tmp % MOD)


fft = FFT()
C = fft.convolve(lst, same)


ans = 0
for i in range(n):
    tmp = A[i] * (lst[i] - C[i]) % MOD
    ans += tmp
    ans %= MOD
print(ans)
0