結果

問題 No.391 CODING WAR
ユーザー tossytossy
提出日時 2016-07-08 23:56:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,274 bytes
コンパイル時間 974 ms
コンパイル使用メモリ 92,640 KB
実行使用メモリ 13,760 KB
最終ジャッジ日時 2024-04-21 08:45:13
合計ジャッジ時間 4,651 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,760 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
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

// 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 m){
    long res =1;
    for(long i=m+1;i<=n;i++) res = res*i%MOD;
    long tmp=1;
    for(long i=1; i<=n-m; i++) tmp = tmp*i%MOD; // (n-m)!
    res = res*mod_pow(tmp, MOD-2, MOD)%MOD; // (n-m)!^(-1)
    return res;
}

long calc(long n, long m){
    if(m==1) return 1;
    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 res;
}

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

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

    cout<<calc(n,m)<<endl;

    return 0;
}
0