結果

問題 No.391 CODING WAR
ユーザー imulanimulan
提出日時 2016-07-09 00:00:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,352 bytes
コンパイル時間 1,864 ms
コンパイル使用メモリ 164,664 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-21 08:47:23
合計ジャッジ時間 5,401 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
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 <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

const ll mod=1e9+7;

ll mod_fact(ll x)
{
    ll ret=1;
    for(ll i=2; i<=x; ++i) (ret*=i)%=mod;
    return ret;
}

//x^n
ll mod_pow(ll x, ll n)
{
    ll ret=1;

    ll pw[40];
    pw[0]=x;
    for(int i=1; i<40; ++i) pw[i]=(pw[i-1]*pw[i-1])%mod;

    rep(i,40)
    {
        if(n>>i&1) (ret*=pw[i])%=mod;
    }

    return ret;
}

ll mod_inv(ll x)
{
    ll pw[32];
    pw[0]=x;
    for(int i=1; i<32; ++i) pw[i]=(pw[i-1]*pw[i-1])%mod;

    ll p=mod-2;
    ll ret=1;
    rep(i,32)
    {
        if(p>>i&1) (ret*=pw[i])%=mod;
    }

    return ret;
}
int main()
{
    ll n,m;
    cin >>n >>m;

    ll ans=0;

    if(n>=m)
    {
        int sgn=1;
        for(ll i=m; i>=1; --i)
        {
            ll mul=1;

            //mCi
            (mul*=mod_fact(m))%=mod;
            (mul*=mod_inv(mod_fact(i)))%=mod;
            (mul*=mod_inv(mod_fact(m-i)))%=mod;

            //i^n
            (mul*=mod_pow(i,n))%=mod;

            ans=(ans+sgn*mul+mod)%mod;
            sgn=-sgn;
        }
    }

    cout << ans << endl;

    return 0;
}
0