結果

問題 No.391 CODING WAR
ユーザー tossytossy
提出日時 2016-07-09 00:03:29
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,219 bytes
コンパイル時間 847 ms
コンパイル使用メモリ 83,620 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-04-21 08:49:54
合計ジャッジ時間 4,503 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,756 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

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