結果

問題 No.2527 H and W
ユーザー tentententen
提出日時 2023-11-07 14:29:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,069 ms / 2,000 ms
コード長 2,418 bytes
コンパイル時間 2,685 ms
コンパイル使用メモリ 92,580 KB
実行使用メモリ 54,828 KB
最終ジャッジ日時 2023-11-07 14:30:03
合計ジャッジ時間 8,416 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
53,396 KB
testcase_01 AC 49 ms
53,396 KB
testcase_02 AC 1,069 ms
54,412 KB
testcase_03 AC 49 ms
53,396 KB
testcase_04 AC 82 ms
53,412 KB
testcase_05 AC 49 ms
53,396 KB
testcase_06 AC 539 ms
53,420 KB
testcase_07 AC 51 ms
53,416 KB
testcase_08 AC 100 ms
54,036 KB
testcase_09 AC 74 ms
53,420 KB
testcase_10 AC 73 ms
53,424 KB
testcase_11 AC 52 ms
53,396 KB
testcase_12 AC 115 ms
54,316 KB
testcase_13 AC 116 ms
54,032 KB
testcase_14 AC 121 ms
54,156 KB
testcase_15 AC 58 ms
54,032 KB
testcase_16 AC 128 ms
54,764 KB
testcase_17 AC 437 ms
54,348 KB
testcase_18 AC 399 ms
54,816 KB
testcase_19 AC 122 ms
54,140 KB
testcase_20 AC 123 ms
54,828 KB
testcase_21 AC 123 ms
54,032 KB
testcase_22 AC 102 ms
54,144 KB
testcase_23 AC 144 ms
54,316 KB
testcase_24 AC 100 ms
54,040 KB
testcase_25 AC 90 ms
53,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static final int MOD = 998244353;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        long h = sc.nextInt();
        long w = sc.nextInt();
        long k = h * w - sc.nextLong();
        long ans = 0;
        for (int i = 0; i <= h && i * w <= k; i++) {
            if ((k - i * w) % (h - i) == 0 && (k - i * w) / (h - i) <= w) {
                ans += getComb(h, i) * getComb(w, (k - i * w) / (h - i)) % MOD;
                ans %= MOD;
            }
        }
        System.out.println(ans);
    }
    
    static long getComb(long a, long b) {
        return fact(a) * pow(fact(a - b) * fact(b) % MOD, MOD - 2) % MOD;
    }
    
    static long fact(long a) {
        long ans = 1;
        for (int i = 2; i <= a; i++) {
            ans *= i;
            ans %= MOD;
        }
        return ans;
    }
    
    static long pow(long x, long p) {
        if (p == 0) {
            return 1;
        } else if (p % 2 == 0) {
            return pow(x * x % MOD, p / 2);
        } else {
            return pow(x, p - 1) * x % MOD;
        }
    }
} 
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0