結果

問題 No.391 CODING WAR
ユーザー nanophoto12nanophoto12
提出日時 2021-05-16 20:26:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 3,070 bytes
コンパイル時間 5,098 ms
コンパイル使用メモリ 257,868 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 11:18:09
合計ジャッジ時間 5,878 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

template<typename T>
void chmax(T& reference, T value) {
    reference = max(reference, value);
}

template<typename T>
void chmaxmap(map<T, T>& m, T key, T value) {
    if (m.count(key)) {
        chmax(m[key], value);
    }
    else {
        m[key] = value;
    }
}

template<typename T>
void chmin(T& reference, T value) {
    reference = min(reference, value);
}


#include <atcoder/all>

using namespace atcoder;

typedef modint1000000007 mint;

struct Point {
    ll x, y;

    bool operator <(const Point& p) const {
        return x < p.x || (x == p.x && y < p.y);
    }
};

struct ConvexHullRunner {
    typedef ll coord_t;
    typedef ll coord2_t;

    coord2_t cross(const Point& O, const Point& A, const Point& B)
    {
        return (A.x - O.x) * (B.y - O.y) - (A.y - O.y) * (B.x - O.x);
    }

    vector<Point> convex_hull(vector<Point> P)
    {
        size_t n = P.size(), k = 0;
        if (n <= 3) return P;
        vector<Point> H(2 * n);

        sort(P.begin(), P.end());

        for (size_t i = 0; i < n; ++i) {
            while (k >= 2 && cross(H[k - 2], H[k - 1], P[i]) <= 0) k--;
            H[k++] = P[i];
        }

        for (size_t i = n - 1, t = k + 1; i > 0; --i) {
            while (k >= t && cross(H[k - 2], H[k - 1], P[i - 1]) <= 0) k--;
            H[k++] = P[i - 1];
        }

        H.resize(k - 1);
        return H;
    }
};

constexpr ll mod = 1000000007;

constexpr ll mpow(ll x, ll n) {
    ll ans = 1; x %= mod;
    while (n != 0) {
        if (n & 1) ans = ans * x % mod;
        x = x * x % mod;
        n = n >> 1;
    }
    return ans;
}

constexpr ll inv_mod(ll a) { return mpow(a, mod - 2); }

class Factorial {
private:
    vector<ll> fac;
    vector<ll> ifac;
public:

    Factorial(ll N) {
        fac.push_back(1);
        for (int i = 0; i < N; i++) fac.push_back(fac[i] * (i + 1) % mod);
        ifac.resize(N + 1);
        ifac[N] = inv_mod(fac[N]);
        for (int i = 0; i < N; i++) ifac[N - 1 - i] = (ifac[N - i] * (N - i)) % mod;
    }

    ll fact(ll a) { return fac[a]; }
    ll ifact(ll a) { return ifac[a]; }

    ll cmb(ll a, ll b) {
        if (a == 0 && b == 0) return 1;
        if (a < b || a < 0 || b < 0) return 0;
        ll tmp = ifact(a - b) * ifact(b) % mod;
        return tmp * fac[a] % mod;
    }
    ll per(ll a, ll b) {
        if (a == 0 && b == 0) return 1;
        if (a < b || a < 0 || b < 0) return 0;
        return fac[a] * ifac[a - b] % mod;
    }
};

int main() {
    ll n, m;
    cin >> n >> m;
    mint sum = 0;
    Factorial f(m + 10);
    int s = 1;
    for (int i = m; i >= 1; i--) {
        mint x = mpow(i, n);
        mint y = f.cmb(m, i);
        sum += x * y * s;
        s *= -1;
    }
    cout << sum.val() << endl;
    return 0;
}
0