結果
問題 | No.391 CODING WAR |
ユーザー | KuroUron |
提出日時 | 2020-06-05 17:44:19 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 113 ms / 2,000 ms |
コード長 | 1,440 bytes |
コンパイル時間 | 614 ms |
コンパイル使用メモリ | 69,376 KB |
実行使用メモリ | 26,740 KB |
最終ジャッジ日時 | 2023-08-22 08:43:06 |
合計ジャッジ時間 | 4,046 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 92 ms
26,460 KB |
testcase_01 | AC | 93 ms
26,468 KB |
testcase_02 | AC | 86 ms
26,452 KB |
testcase_03 | AC | 90 ms
26,412 KB |
testcase_04 | AC | 91 ms
26,472 KB |
testcase_05 | AC | 91 ms
26,520 KB |
testcase_06 | AC | 95 ms
26,536 KB |
testcase_07 | AC | 92 ms
26,476 KB |
testcase_08 | AC | 88 ms
26,392 KB |
testcase_09 | AC | 105 ms
26,740 KB |
testcase_10 | AC | 112 ms
26,456 KB |
testcase_11 | AC | 100 ms
26,380 KB |
testcase_12 | AC | 94 ms
26,528 KB |
testcase_13 | AC | 108 ms
26,440 KB |
testcase_14 | AC | 105 ms
26,476 KB |
testcase_15 | AC | 113 ms
26,532 KB |
testcase_16 | AC | 98 ms
26,540 KB |
testcase_17 | AC | 98 ms
26,484 KB |
testcase_18 | AC | 92 ms
26,528 KB |
testcase_19 | AC | 91 ms
26,448 KB |
ソースコード
#include <iostream> #include <vector> long long modpow(int a, long long n, int mod) { long long res = 1; long long apow = a; // a^1, a^2, a^4, ... while (n) { if (n & 1LL) res = (res * apow) % mod; apow = apow * apow % mod; n = n >> 1; } return res; } class Combination { private: const int max; const int mod; std::vector<long long> fac; // fac[k] = k! in Fp std::vector<long long> finv; // finv[k] = (k!)^-1 in Fp public: Combination(int max, int mod) : max(max), mod(mod), fac(max, -1), finv(max, -1) { std::vector<long long> inv(max, -1); // inv[k] = k^-1 in Fp fac[0] = fac[1] = 1; inv[1] = 1; finv[0] = finv[1] = 1; for (int i = 2; i < max; ++i) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } long long operator()(int n, int k) const { if (n < k || n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } }; int main() { long long N; int M; std::cin >> N >> M; int mod = 1000000007; const int MAX = 1000000; Combination comb(MAX, mod); long long res = 0; for (int j = 0; j <= M; ++j) { long long tmp = 1; tmp = tmp * modpow(j, N, mod) % mod; tmp = tmp * comb(M, j) % mod; if ((M - j) % 2 == 1) tmp = mod - 1 * tmp; res = (res + tmp) % mod; } std::cout << res << std::endl; }