結果

問題 No.1035 Color Box
ユーザー renjyaku_intrenjyaku_int
提出日時 2020-04-25 20:12:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 2,347 bytes
コンパイル時間 1,668 ms
コンパイル使用メモリ 165,764 KB
実行使用メモリ 18,944 KB
最終ジャッジ日時 2024-04-25 08:07:20
合計ジャッジ時間 8,021 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 145 ms
18,816 KB
testcase_01 AC 139 ms
18,816 KB
testcase_02 AC 140 ms
18,944 KB
testcase_03 AC 142 ms
18,816 KB
testcase_04 AC 142 ms
18,816 KB
testcase_05 AC 143 ms
18,816 KB
testcase_06 AC 139 ms
18,816 KB
testcase_07 AC 138 ms
18,816 KB
testcase_08 AC 147 ms
18,944 KB
testcase_09 AC 145 ms
18,816 KB
testcase_10 AC 143 ms
18,816 KB
testcase_11 AC 142 ms
18,816 KB
testcase_12 AC 142 ms
18,944 KB
testcase_13 AC 148 ms
18,816 KB
testcase_14 AC 145 ms
18,944 KB
testcase_15 AC 149 ms
18,944 KB
testcase_16 AC 147 ms
18,944 KB
testcase_17 AC 143 ms
18,816 KB
testcase_18 AC 139 ms
18,816 KB
testcase_19 AC 147 ms
18,816 KB
testcase_20 AC 143 ms
18,944 KB
testcase_21 AC 139 ms
18,944 KB
testcase_22 AC 144 ms
18,944 KB
testcase_23 AC 141 ms
18,944 KB
testcase_24 AC 143 ms
18,816 KB
testcase_25 AC 143 ms
18,816 KB
testcase_26 AC 141 ms
18,816 KB
testcase_27 AC 140 ms
18,944 KB
testcase_28 AC 143 ms
18,816 KB
testcase_29 AC 144 ms
18,944 KB
testcase_30 AC 142 ms
18,944 KB
testcase_31 AC 143 ms
18,816 KB
testcase_32 AC 145 ms
18,816 KB
testcase_33 AC 140 ms
18,816 KB
testcase_34 AC 153 ms
18,816 KB
testcase_35 AC 143 ms
18,944 KB
testcase_36 AC 143 ms
18,816 KB
testcase_37 AC 141 ms
18,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, m;
const ll M = pow(10, 9) + 7;

vector<ll> fac(1000001);  //n!(mod M)
vector<ll> ifac(1000001); //k!^{M-2} (mod M)
ll mpow(ll x, ll n)
{ //x^n(mod M)
    ll ans = 1;
    while (n != 0)
    {
        if (n & 1)
            ans = ans * x % M;
        x = x * x % M;
        n = n >> 1;
    }
    return ans;
}
//conbination
ll comb(ll a, ll b)
{ //aCb(mod M)
    if (a == 0 && b == 0)
        return 1;
    if (a < b || a < 0)
        return 0;
    ll tmp = ifac[a - b] * ifac[b] % M;
    return tmp * fac[a] % M;
}
ll fact_mod(ll n)
{
    ll ret = 1;
    for (ll i = 2; i <= n; i++)
        ret = ret * (i % MOD) % MOD;
    return ret;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    fac[0] = 1;
    ifac[0] = 1;
    for (ll i = 0; i < 1000000; i++)
    {
        fac[i + 1] = fac[i] * (i + 1) % M;              // n!(mod M)
        ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M)
    }
    ll ans=0;
    for(ll i=0;i<=m;i++){
        if(i%2)
        ans-=comb(m,i)*mpow(m-i,n);
        else
        {
            ans += comb(m, i) * mpow(m - i, n);
        }
        ans=(ans+MOD)%MOD;
    }
    
    cout << ans<< "\n";
}
0