結果
問題 | No.2245 Second Smallest |
ユーザー | chro_96 |
提出日時 | 2023-03-11 13:44:21 |
言語 | C (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 31 ms / 2,000 ms |
コード長 | 2,144 bytes |
コンパイル時間 | 1,832 ms |
コンパイル使用メモリ | 32,384 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-18 06:20:42 |
合計ジャッジ時間 | 3,174 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 31 ms
5,376 KB |
testcase_06 | AC | 31 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 3 ms
5,376 KB |
testcase_09 | AC | 31 ms
5,376 KB |
testcase_10 | AC | 20 ms
5,376 KB |
testcase_11 | AC | 18 ms
5,376 KB |
testcase_12 | AC | 16 ms
5,376 KB |
testcase_13 | AC | 8 ms
5,376 KB |
testcase_14 | AC | 14 ms
5,376 KB |
testcase_15 | AC | 19 ms
5,376 KB |
testcase_16 | AC | 6 ms
5,376 KB |
testcase_17 | AC | 7 ms
5,376 KB |
testcase_18 | AC | 14 ms
5,376 KB |
testcase_19 | AC | 20 ms
5,376 KB |
testcase_20 | AC | 16 ms
5,376 KB |
testcase_21 | AC | 12 ms
5,376 KB |
testcase_22 | AC | 19 ms
5,376 KB |
testcase_23 | AC | 4 ms
5,376 KB |
testcase_24 | AC | 20 ms
5,376 KB |
testcase_25 | AC | 8 ms
5,376 KB |
testcase_26 | AC | 3 ms
5,376 KB |
testcase_27 | AC | 27 ms
5,376 KB |
testcase_28 | AC | 7 ms
5,376 KB |
testcase_29 | AC | 6 ms
5,376 KB |
ソースコード
#include <stdio.h> long long power_mod (long long a, long long b, long long mod_num) { long long ans = 1LL; if (b > 0LL) { ans = power_mod(a, b/2LL, mod_num); ans = (ans * ans) % mod_num; if (b%2LL == 1LL) { ans = (ans * (a % mod_num)) % mod_num; } } return ans; } int main () { int h = 0; int w = 0; int k = 0; int res = 0; long long ans = 0LL; long long mod_num = 998244353; long long hw = 0LL; long long div = 1LL; long long fact[60001] = {}; long long invf[60001] = {}; res = scanf("%d", &h); res = scanf("%d", &w); res = scanf("%d", &k); if (h > w) { int swap = h; h = w; w = swap; } hw = ((long long)h)*((long long)w); for (int i = 0; i < k; i++) { div *= hw+((long long)(k-i)); div %= mod_num; } fact[0] = 1LL; for (int i = 0; i < w+k; i++) { fact[i+1] = fact[i]; fact[i+1] *= (long long) (i+1); fact[i+1] %= mod_num; } invf[w+k] = power_mod(fact[w+k], mod_num-2LL, mod_num); for (int i = w+k; i > 0; i--) { invf[i-1] = invf[i]; invf[i-1] *= (long long)i; invf[i-1] %= mod_num; } div = (div*hw)%mod_num; for (int i = 1; i <= h; i++) { long long tmp = hw-((long long)i); tmp *= fact[h]; tmp %= mod_num; tmp *= invf[i]; tmp %= mod_num; tmp *= invf[h-i]; tmp %= mod_num; tmp *= fact[w]; tmp %= mod_num; tmp *= invf[i]; tmp %= mod_num; tmp *= invf[w-i]; tmp %= mod_num; tmp *= fact[i]; tmp %= mod_num; if (i < h) { long long sub = fact[h]; sub *= invf[i+1]; sub %= mod_num; sub *= invf[h-i-1]; sub %= mod_num; sub *= fact[w]; sub %= mod_num; sub *= invf[i+1]; sub %= mod_num; sub *= invf[w-i-1]; sub %= mod_num; sub *= fact[i+1]; tmp += mod_num-sub%mod_num; tmp %= mod_num; } tmp *= fact[i+k]; tmp %= mod_num; tmp *= invf[i]; tmp %= mod_num; div *= hw-((long long)i); div %= mod_num; ans += (tmp*power_mod(div, mod_num-2LL, mod_num))%mod_num; } printf("%lld\n", ans%mod_num); return 0; }