結果

問題 No.1035 Color Box
ユーザー snow39
提出日時 2021-08-10 22:26:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 4,517 bytes
コンパイル時間 1,185 ms
コンパイル使用メモリ 107,252 KB
最終ジャッジ日時 2025-01-23 17:26:02
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define mkp make_pair
#define mkt make_tuple
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
template <class T>
void chmin(T& a, const T& b) {
if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
if (a < b) a = b;
}
template <long long mod>
class modint {
private:
using T = long long;
T a;
public:
constexpr modint(const long long x = 0) noexcept : a((x % mod + mod) % mod) {}
constexpr T& value() noexcept {
return a;
}
constexpr const T& value() const noexcept {
return a;
}
constexpr modint operator-() const noexcept {
return modint(0) -= *this;
}
constexpr modint operator+(const modint& rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint& rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint& rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint& rhs) const noexcept {
return modint(*this) /= rhs;
}
constexpr modint& operator+=(const modint& rhs) noexcept {
a += rhs.a;
if (a >= mod) a -= mod;
return *this;
}
constexpr modint& operator-=(const modint& rhs) noexcept {
if (a < rhs.a) a += mod;
a -= rhs.a;
return *this;
}
constexpr modint& operator*=(const modint& rhs) noexcept {
a = a * rhs.a % mod;
return *this;
}
constexpr modint& operator/=(const modint& rhs) noexcept {
return *this *= rhs.inv();
}
constexpr bool operator==(const modint& rhs) const noexcept {
return a == rhs.a;
}
constexpr bool operator!=(const modint& rhs) const noexcept {
return not(*this == rhs);
}
constexpr modint pow(long long k) const noexcept {
modint ret(1);
modint x = k > 0 ? *this : this->inv();
k = abs(k);
while (k > 0) {
if (k & 1) ret *= x;
x *= x;
k >>= 1;
}
return ret;
}
constexpr modint inv() const noexcept {
return pow(mod - 2);
}
friend std::ostream& operator<<(std::ostream& os, const modint& X) noexcept {
return os << X.a;
}
friend std::istream& operator>>(std::istream& is, modint& X) noexcept {
is >> X.a;
X.a %= mod;
if (X.a < 0) X.a += mod;
return is;
}
};
template <typename T>
struct Combination {
int MAX_N = 1'000'010;
vector<T> fac, ifac, inv;
Combination(int MAX_N = 1'000'010) : MAX_N(MAX_N), fac(MAX_N), ifac(MAX_N), inv(MAX_N) {
fac[0] = 1, ifac[0] = 1, inv[0] = 1;
for (int i = 1; i < MAX_N; ++i) {
fac[i] = fac[i - 1] * i;
}
ifac[MAX_N - 1] = T(1) / fac[MAX_N - 1];
for (int i = MAX_N - 1; i > 0; --i) {
ifac[i - 1] = ifac[i] * i;
}
for (int i = MAX_N - 1; i > 0; --i) {
inv[i] = ifac[i] * fac[i - 1];
}
}
T perm(int n, int k) {
if (n < k || n < 0 || k < 0)
return 0;
else
return fac[n] * ifac[n - k];
}
T comb(int n, int k) {
if (n < k || n < 0 || k < 0)
return 0;
else
return fac[n] * ifac[k] * ifac[n - k];
}
T hcomb(int n, int r) { // this size is really ok??
if (n == 0 && r == 0)
return 1;
else if (n < 0 || r < 0)
return 0;
else
return comb(n + r - 1, r);
}
T binom(ll _n, int k) {
if (_n < k || _n < 0 || k < 0) return 0;
T n = _n;
T res = 1;
for (int i = 0; i < k; i++) res = res * (n - i);
res *= ifac[k];
return res;
}
};
using mint = modint<1000000007>;
void solve() {
Combination<mint> math;
int N, M;
cin >> N >> M;
vector<mint> dp(M + 1, 0);
for (int i = 1; i <= M; i++) {
mint res = math.comb(M, i) * mint(i).pow(N);
res -= dp[i - 1];
dp[i] = res;
}
mint ans = dp[M];
cout << ans << endl;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
solve();
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0