結果

問題 No.1035 Color Box
ユーザー iqueue02iqueue02
提出日時 2020-04-25 11:14:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,192 bytes
コンパイル時間 1,794 ms
コンパイル使用メモリ 167,016 KB
実行使用メモリ 15,660 KB
最終ジャッジ日時 2023-08-06 17:26:51
合計ジャッジ時間 3,676 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
15,312 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 20 ms
15,392 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 47 ms
15,320 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 17 ms
15,348 KB
testcase_12 WA -
testcase_13 AC 42 ms
15,284 KB
testcase_14 AC 48 ms
15,376 KB
testcase_15 AC 51 ms
15,288 KB
testcase_16 AC 17 ms
15,320 KB
testcase_17 AC 17 ms
15,284 KB
testcase_18 AC 17 ms
15,260 KB
testcase_19 AC 52 ms
15,380 KB
testcase_20 AC 17 ms
15,380 KB
testcase_21 AC 18 ms
15,268 KB
testcase_22 AC 17 ms
15,280 KB
testcase_23 AC 18 ms
15,312 KB
testcase_24 AC 17 ms
15,316 KB
testcase_25 AC 17 ms
15,284 KB
testcase_26 AC 17 ms
15,372 KB
testcase_27 AC 17 ms
15,352 KB
testcase_28 AC 17 ms
15,392 KB
testcase_29 AC 17 ms
15,460 KB
testcase_30 AC 16 ms
15,316 KB
testcase_31 AC 17 ms
15,464 KB
testcase_32 AC 17 ms
15,316 KB
testcase_33 AC 17 ms
15,324 KB
testcase_34 AC 17 ms
15,280 KB
testcase_35 AC 18 ms
15,412 KB
testcase_36 AC 18 ms
15,316 KB
testcase_37 AC 17 ms
15,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
const int MAX = 510000;
const ll MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[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 COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll mod_pow(ll x, ll n, ll mod = MOD){
    if(n == 0)return 1;
    ll res = mod_pow(x*x%mod,n/2,mod);
    if(n&1) res = res * x % mod;
    return res;
}
int main() {
  ll n, m;
  cin >> n >> m;
  COMinit();
  ll res = mod_pow(m, n);

  int cnt = 0;
  for (int x = m - 1; x >= 1; x--) {
    ll now = COM(m, x) * mod_pow(x, n);
    if (cnt % 2 == 0) res = res - now + MOD;
    else res += now;
    cnt++;
    res %= MOD;
  }
  cout << res << endl;
  return 0; 
}   
0