結果

問題 No.2527 H and W
ユーザー LyricalMaestroLyricalMaestro
提出日時 2024-01-07 11:44:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 1,915 bytes
コンパイル時間 542 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 90,972 KB
最終ジャッジ日時 2024-01-07 11:44:16
合計ジャッジ時間 4,040 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,588 KB
testcase_01 AC 35 ms
53,588 KB
testcase_02 AC 95 ms
90,572 KB
testcase_03 AC 35 ms
53,588 KB
testcase_04 AC 110 ms
90,580 KB
testcase_05 AC 110 ms
90,580 KB
testcase_06 AC 113 ms
90,972 KB
testcase_07 AC 34 ms
53,588 KB
testcase_08 AC 94 ms
90,572 KB
testcase_09 AC 94 ms
90,572 KB
testcase_10 AC 93 ms
90,572 KB
testcase_11 AC 110 ms
90,580 KB
testcase_12 AC 108 ms
90,580 KB
testcase_13 AC 106 ms
90,580 KB
testcase_14 AC 97 ms
90,580 KB
testcase_15 AC 109 ms
90,580 KB
testcase_16 AC 93 ms
90,572 KB
testcase_17 AC 94 ms
90,572 KB
testcase_18 AC 94 ms
90,572 KB
testcase_19 AC 72 ms
77,252 KB
testcase_20 AC 74 ms
80,756 KB
testcase_21 AC 93 ms
90,572 KB
testcase_22 AC 94 ms
90,572 KB
testcase_23 AC 93 ms
90,572 KB
testcase_24 AC 73 ms
80,068 KB
testcase_25 AC 84 ms
85,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/2527

import math

MOD = 998244353


class CombinationCalculator:
    """
    modを考慮したPermutation, Combinationを計算するためのクラス
    """    
    def __init__(self, size, mod):
        self.mod = mod
        self.factorial = [0] * (size + 1)
        self.factorial[0] = 1
        for i in range(1, size + 1):
            self.factorial[i] = (i * self.factorial[i - 1]) % self.mod
        
        self.inv_factorial = [0] * (size + 1)
        self.inv_factorial[size] = pow(self.factorial[size], self.mod - 2, self.mod)

        for i in reversed(range(size)):
            self.inv_factorial[i] = ((i + 1) * self.inv_factorial[i + 1]) % self.mod

    def calc_combination(self, n, r):
        if n < 0 or n < r:
            return 0

        if r == 0 or n == r:
            return 1
        
        ans = self.inv_factorial[n - r] * self.inv_factorial[r]
        ans %= self.mod
        ans *= self.factorial[n]
        ans %= self.mod
        return ans
    
    def calc_permutation(self, n, r):
        if n < 0 or n < r:
            return 0

        ans = self.inv_factorial[n - r]
        ans *= self.factorial[n]
        ans %= self.mod
        return ans
        

def main():
    H, W, K = map(int, input().split())

    # Kの約数列挙
    sqrt_k = int(math.sqrt(K))
    array = []
    for p in range(1, sqrt_k + 1):
        if K % p == 0:
            q = K // p
            array.append(p)
            if p != q:
                array.append(q)
    
    combi = CombinationCalculator(max(H, W), MOD)
    answer = 0
    for h in array:
        if h > H:
            continue
        w = K // h
        if w > W:
            continue
        h0 = H - h 
        w0 = W - w
        answer += (combi.calc_combination(H, h0) * combi.calc_combination(W, w0)) % MOD
        answer %= MOD
    print(answer)



if __name__ == "__main__":
    main()
0