結果

問題 No.391 CODING WAR
ユーザー tossytossy
提出日時 2016-07-09 00:03:29
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,219 bytes
コンパイル時間 641 ms
コンパイル使用メモリ 82,436 KB
実行使用メモリ 10,916 KB
最終ジャッジ日時 2024-10-13 07:42:00
合計ジャッジ時間 4,330 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 3 WA * 2 TLE * 1 -- * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <fstream>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
typedef long long ll;

#define INF 1000000000
#define MOD 1000000007

long dp[100000];

// x^n mod
long mod_pow(long x, long n, long mod){
  long res=1;
  while(n>0){
    if(n&1) res=res*x%mod;
    x=x*x%mod;
    n>>=1;
  }
  return res;
}

long comb(long n, long r){
    long p=1;
    for (long i=1;i<=r;i++)
        p=p*(n-i+1)/i;
    return p%MOD;
}

long calc(long n, long m){
    if(dp[m]!=-1) return dp[m];
    long res = mod_pow(m,n,MOD);
    for(long i=m-1; i>=1; i--){
        res = (res - comb(m,i)*calc(n, i) + MOD)%MOD;
    }
    return dp[m] = res;
}

int main(){
    long n,m;
    cin>>n>>m;

    if(m>n){ cout<<0<<endl; return 0; }

    fill(dp, dp+m+1, -1);
    dp[1]=1;
    cout<<calc(n,m)<<endl;

    return 0;
}
0