結果
問題 | No.1035 Color Box |
ユーザー |
|
提出日時 | 2020-04-24 22:33:53 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 37 ms / 2,000 ms |
コード長 | 860 bytes |
コンパイル時間 | 1,547 ms |
コンパイル使用メモリ | 170,112 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-15 03:13:10 |
合計ジャッジ時間 | 2,941 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h>#define rep(i, n) for (int i = 0; i < n; i++)using namespace std;typedef long long ll;ll mod_pow(ll x, ll n, ll mod) {ll res = 1;while (n > 0) {if (n & 1) res = res * x % mod;x = x * x % mod;n >>= 1;}return res;}int main() {ll MOD = 1e9 + 7;vector<ll> f(100001, 1);rep(i, 100000) f[i + 1] = (f[i] * (i + 1)) % MOD;ll N, M;cin >> N >> M;ll ans = mod_pow(M, N, MOD);for (int i = M - 1; i >= 1; i--) {ll d = mod_pow(i, N, MOD) * f[M];d %= MOD;d *= mod_pow(f[i], MOD - 2, MOD);d %= MOD;d *= mod_pow(f[M - i], MOD - 2, MOD);d %= MOD;if ((M - i) % 2) {ans = (ans - d + MOD) % MOD;} else {ans = (ans + d) % MOD;}}cout << ans << "\n";}