結果

問題 No.1655 123 Swaps
ユーザー Kiri8128Kiri8128
提出日時 2021-06-25 00:00:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,842 ms / 2,000 ms
コード長 2,838 bytes
コンパイル時間 999 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 227,340 KB
最終ジャッジ日時 2024-10-14 02:16:10
合計ジャッジ時間 33,378 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

p, g, ig = 924844033, 5, 554906420
W = [pow(g, (p - 1) >> i, p) for i in range(24)]
iW = [pow(ig, (p - 1) >> i, p) for i in range(24)]

def convolve(a, b):
    def fft(f):
        for l in range(k, 0, -1):
            d = 1 << l - 1
            U = [1]
            for i in range(d):
                U.append(U[-1] * W[l] % p)

            for i in range(1 << k - l):
                for j in range(d):
                    s = i * 2 * d + j
                    t = s + d
                    f[s], f[t] = (f[s] + f[t]) % p, U[j] * (f[s] - f[t]) % p

    def ifft(f):
        for l in range(1, k + 1):
            d = 1 << l - 1
            U = [1]
            for i in range(d):
                U.append(U[-1] * iW[l] % p)

            for i in range(1 << k - l):
                for j in range(d):
                    s = i * 2 * d + j
                    t = s + d
                    f[s], f[t] = (f[s] + f[t] * U[j]) % p, (f[s] - f[t] * U[j]) % p

    n0 = len(a) + len(b) - 1
    if len(a) < 50 or len(b) < 50:
        ret = [0] * n0
        if len(a) > len(b): a, b = b, a
        for i, aa in enumerate(a):
            for j, bb in enumerate(b):
                ret[i+j] = (ret[i+j] + aa * bb) % p
        return ret
    
    k = (n0).bit_length()
    n = 1 << k
    a = a + [0] * (n - len(a))
    b = b + [0] * (n - len(b))
    fft(a), fft(b)
    for i in range(n):
        a[i] = a[i] * b[i] % p
    ifft(a)
    invn = pow(n, p - 2, p)
    for i in range(n0):
        a[i] = a[i] * invn % p
    del a[n0:]
    return a

P = 924844033
nn = 600600

fa = [1] * (nn+1)
fainv = [1] * (nn+1)
for i in range(nn):
    fa[i+1] = fa[i] * (i+1) % P
fainv[-1] = pow(fa[-1], P-2, P)
for i in range(nn)[::-1]:
    fainv[i] = fainv[i+1] * (i+1) % P

def calc(a, b, c):
    M = a + b + c
    if M % 2: return 0
    M //= 2
    i3 = pow(3, P - 2, P)
    re = 0
    A = [[0] * (a + 1) for _ in range(3)]
    B = [[0] * (b + 1) for _ in range(3)]
    
    for i in range(a + 1):
        A[(2*i-a)%3][i] = fainv[i] * fainv[a-i] % P
    for i in range(b + 1):
        B[(b-2*i)%3][i] = fainv[i] * fainv[b-i] % P
    
    AB = [[0] * (a + b + 1) for _ in range(2)]
    for k1 in range(3):
        for k2 in range(3):
            k = (k1 + k2) % 3
            if k == 2: continue
            ab = AB[k]
            for i, x in enumerate(convolve(A[k1], B[k2])):
                ab[i] = (ab[i] + x) % P
    
    RE = [0] * 2
    for k, ab in enumerate(AB):
        for i, x in enumerate(ab):
            if i > M: continue
            j = M - a - b + i
            if j < 0: continue
            RE[k] = (RE[k] + x * fainv[M-i] * fainv[j]) % P
    
    re = RE[0] - RE[1]
    re = re * fa[M] ** 2 % P * 2 * i3 % P
    re = (re + fa[M*2] * fainv[a] * fainv[b] * fainv[c] * i3) % P
    return re

a, b, c = map(int, input().split())
print(calc(a, b, c))


0