結果

問題 No.391 CODING WAR
ユーザー CleyLCleyL
提出日時 2023-06-29 15:28:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,295 bytes
コンパイル時間 644 ms
コンパイル使用メモリ 74,040 KB
実行使用メモリ 5,420 KB
最終ジャッジ日時 2023-09-20 10:51:05
合計ジャッジ時間 2,340 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 23 ms
5,400 KB
testcase_10 AC 22 ms
5,420 KB
testcase_11 AC 12 ms
5,372 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 19 ms
5,396 KB
testcase_14 AC 17 ms
4,936 KB
testcase_15 AC 18 ms
5,276 KB
testcase_16 AC 12 ms
4,380 KB
testcase_17 AC 14 ms
4,376 KB
testcase_18 AC 10 ms
4,376 KB
testcase_19 AC 10 ms
4,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

const long long MOD = 1000000007;

template <int mod>
struct Combination {
  long long n_max;
  vector<long long> fac, inv, finv;
  Combination(int n):n_max(n), fac(n+1,1), inv(n+1,1), finv(n+1,1){
    for(int i = 2; n > i; 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 C(int n, int r){
    if(n < r)return 0;
    if(n > n_max)return 0;
    return (((fac[n]*finv[r])%mod)*finv[n-r])%mod;
  }

  long long P(int n, int r){
    if(n < r)return 0;
    if(n > n_max)return 0;
    return (fac[n]*finv[n-r])%mod;
  }

  long long H(int n, int r){
    if(n==0 && r==0)return 1;
    return C(n+r-1, r);
  }
};
using comb = Combination<MOD>;

template <typename T>
T uPow(T z,T n, T mod){
  T ans = 1;
  while(n != 0){
    if(n%2){
      ans*=z;
      if(mod)ans%=mod;
    }
    n >>= 1;
    z*=z;
    if(mod)z%=mod;
  }
  return ans;
}

int main(){
  long long n,m;cin>>n>>m;
  comb c(m+1);
  int sign = (m%2 == 0 ? 1 : -1);
  long long ans = 0;
  for(long long i = 0; m >= i; i++){
    long long tmp = (c.C(m,i)*uPow(i,n,MOD))%MOD;
    if(sign == -1)tmp = MOD - tmp;
    ans = (ans + tmp)%MOD;
    sign *= -1;
  }
  cout << ans << endl;
}
0