結果

問題 No.391 CODING WAR
ユーザー shinchanshinchan
提出日時 2020-04-30 15:15:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,126 bytes
コンパイル時間 3,019 ms
コンパイル使用メモリ 199,168 KB
実行使用メモリ 8,296 KB
最終ジャッジ日時 2023-08-22 04:15:42
合計ジャッジ時間 3,613 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
8,088 KB
testcase_01 AC 8 ms
8,032 KB
testcase_02 AC 8 ms
8,076 KB
testcase_03 AC 8 ms
8,104 KB
testcase_04 AC 8 ms
8,032 KB
testcase_05 AC 8 ms
8,088 KB
testcase_06 AC 8 ms
8,044 KB
testcase_07 AC 8 ms
8,032 KB
testcase_08 AC 8 ms
8,128 KB
testcase_09 AC 26 ms
8,160 KB
testcase_10 AC 25 ms
8,088 KB
testcase_11 AC 15 ms
8,088 KB
testcase_12 AC 8 ms
8,212 KB
testcase_13 AC 22 ms
8,064 KB
testcase_14 AC 21 ms
8,060 KB
testcase_15 AC 23 ms
8,028 KB
testcase_16 AC 17 ms
8,296 KB
testcase_17 AC 19 ms
8,076 KB
testcase_18 AC 15 ms
8,052 KB
testcase_19 AC 15 ms
8,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

ll fac[200007],finv[200007],inv[200007];
void cominit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<200007;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;
    }
}
ll com(ll n,ll k){
    if(n<k)return 0;
    if(n<0 || k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cominit();
    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    for(ll i=0;i<=m;i++){
    	ans += ((com(m, i) * modpow(i, n))%mod * (((m-i)&1? -1: 1)))%mod;
    	ans %= mod;
    }
    cout << (ans+mod)%mod << endl;
    return 0;
}
0