結果

問題 No.391 CODING WAR
ユーザー ayanamizutaayanamizuta
提出日時 2019-01-29 12:02:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,207 bytes
コンパイル時間 1,248 ms
コンパイル使用メモリ 160,268 KB
実行使用メモリ 11,344 KB
最終ジャッジ日時 2024-04-17 18:37:09
合計ジャッジ時間 2,317 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
11,244 KB
testcase_01 AC 8 ms
11,296 KB
testcase_02 AC 9 ms
11,164 KB
testcase_03 AC 8 ms
11,212 KB
testcase_04 AC 8 ms
11,140 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 9 ms
11,240 KB
testcase_07 AC 8 ms
11,344 KB
testcase_08 AC 8 ms
11,120 KB
testcase_09 AC 48 ms
11,024 KB
testcase_10 AC 48 ms
11,172 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 8 ms
11,148 KB
testcase_13 AC 45 ms
11,124 KB
testcase_14 AC 38 ms
11,112 KB
testcase_15 AC 41 ms
11,068 KB
testcase_16 AC 29 ms
11,140 KB
testcase_17 AC 33 ms
11,156 KB
testcase_18 AC 24 ms
11,268 KB
testcase_19 AC 24 ms
11,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

#define MOD 1000000007
#define FACT_MAX 1000000

LL fact[FACT_MAX];

class Combinatrics{
private:
  long long mod = MOD;
  int fact_max = FACT_MAX;
public:
  Combinatrics(){
    fact[0]=1;
    for(int i=1;i<fact_max;i++)
      fact[i] = (fact[i-1]*i)%mod;
  }
  
  long long power(long long n, long long e){
    long long ret = 1;
    long long b = n;
    while(e){
      if(e%2!=0)
	ret*=b;
      ret%=mod;
      b*=b;
      b%=mod;
      e/=2;
    }
    return ret;
  }

  long long inv(long long n){
    return power(n,mod-2);
  }

  long long div(long long n1,long long n2){
    return n1*power(n2,mod-2)%mod;
  }
  
  long long nck(int n,int k){
    if(k>n || k<0) return 0LL;
    if(k==n || k==0) return 1LL;
    return (fact[n]*inv(fact[n-k])%mod)*inv(fact[k])%mod;
  }
};

LL n;
int m;

int main(){
  cin>>n>>m;
  if(n<(LL)m){cout<<0<<endl;return 0;}
  LL ret=0;
  Combinatrics comb;
  REP(i,m){
    ret=(i%2)?(MOD+ret-comb.nck(m,i)*comb.power((LL)(m-i),n)%MOD)%MOD:(ret+comb.nck(m,i)*comb.power((LL)(m-i),n)%MOD)%MOD;
  }
  cout<<ret<<endl;
  return 0;
}
0