結果
問題 | No.1846 Good Binary Matrix |
ユーザー | 👑 ygussany |
提出日時 | 2022-02-18 22:33:00 |
言語 | C (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 244 ms / 2,000 ms |
コード長 | 1,126 bytes |
コンパイル時間 | 471 ms |
コンパイル使用メモリ | 30,880 KB |
実行使用メモリ | 17,488 KB |
最終ジャッジ日時 | 2023-09-11 19:35:43 |
合計ジャッジ時間 | 3,989 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | AC | 1 ms
4,376 KB |
testcase_08 | AC | 1 ms
4,376 KB |
testcase_09 | AC | 1 ms
4,376 KB |
testcase_10 | AC | 1 ms
4,384 KB |
testcase_11 | AC | 1 ms
4,376 KB |
testcase_12 | AC | 1 ms
4,380 KB |
testcase_13 | AC | 1 ms
4,380 KB |
testcase_14 | AC | 1 ms
4,376 KB |
testcase_15 | AC | 1 ms
4,376 KB |
testcase_16 | AC | 242 ms
17,488 KB |
testcase_17 | AC | 230 ms
16,840 KB |
testcase_18 | AC | 232 ms
17,016 KB |
testcase_19 | AC | 231 ms
16,776 KB |
testcase_20 | AC | 244 ms
17,388 KB |
testcase_21 | AC | 1 ms
4,380 KB |
testcase_22 | AC | 1 ms
4,376 KB |
testcase_23 | AC | 1 ms
4,380 KB |
testcase_24 | AC | 1 ms
4,376 KB |
testcase_25 | AC | 175 ms
16,192 KB |
testcase_26 | AC | 112 ms
12,116 KB |
testcase_27 | AC | 7 ms
4,380 KB |
testcase_28 | AC | 26 ms
6,732 KB |
testcase_29 | AC | 75 ms
11,936 KB |
testcase_30 | AC | 60 ms
7,852 KB |
testcase_31 | AC | 28 ms
6,884 KB |
testcase_32 | AC | 178 ms
16,132 KB |
testcase_33 | AC | 31 ms
6,812 KB |
testcase_34 | AC | 1 ms
4,376 KB |
ソースコード
#include <stdio.h> const long long Mod = 1000000007; long long fact[1000001], fact_inv[1000001]; long long combination(int n, int k) { if (k < 0 || n < k) return 0; return fact[n] * fact_inv[k] % Mod * fact_inv[n-k] % Mod; } long long div_mod(long long x, long long y, long long z) { if (x % y == 0) return x / y; else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y; } long long pow_mod(int n, long long k) { long long N, ans = 1; for (N = n; k > 0; k >>= 1, N = N * N % Mod) if (k & 1) ans = ans * N % Mod; return ans; } int main() { int H, W; scanf("%d %d", &H, &W); if (H > W) { H ^= W; W ^= H; H ^= W; } int h; long long ans = 0, tmp; for (h = 1, fact[0] = 1; h <= H; h++) fact[h] = fact[h-1] * h % Mod; for (h = H - 1, fact_inv[H] = div_mod(1, fact[H], Mod); h >= 0; h--) fact_inv[h] = fact_inv[h+1] * (h + 1) % Mod; for (h = 0; h <= H; h++) { if (h % 2 == 0) ans += combination(H, h) * (pow_mod(pow_mod(2, H - h) - 1, W)) % Mod; else ans += Mod - combination(H, h) * (pow_mod(pow_mod(2, H - h) - 1, W)) % Mod; } printf("%lld\n", ans % Mod); fflush(stdout); return 0; }