結果

問題 No.1035 Color Box
ユーザー outline
提出日時 2020-12-14 23:56:21
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 3,941 bytes
コンパイル時間 1,120 ms
コンパイル使用メモリ 130,588 KB
最終ジャッジ日時 2025-01-17 00:37:54
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

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

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;
template<class T>
inline bool chmax(T& x, T y){
if(x < y){
x = y;
return true;
}
return false;
}
template<class T>
inline bool chmin(T& x, T y){
if(x > y){
x = y;
return true;
}
return false;
}
struct mint {
int x;
mint() : x(0) {}
mint(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
mint& operator+=(const mint& p){
if((x += p.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint& p){
if((x -= p.x) < 0) x += mod;
return *this;
}
mint& operator*=(const mint& p){
x = (int)(1LL * x * p.x % mod);
return *this;
}
mint& operator/=(const mint& p){
*this *= p.inverse();
return *this;
}
mint operator-() const { return mint(-x); }
mint operator+(const mint& p) const { return mint(*this) += p; }
mint operator-(const mint& p) const { return mint(*this) -= p; }
mint operator*(const mint& p) const { return mint(*this) *= p; }
mint operator/(const mint& p) const { return mint(*this) /= p; }
bool operator==(const mint& p) const { return x == p.x; }
bool operator!=(const mint& p) const { return x != p.x; }
mint pow(int64_t n) const {
mint res = 1, mul = x;
while(n > 0){
if(n & 1) res *= mul;
mul *= mul;
n >>= 1;
}
return res;
}
mint inverse() const { return pow(mod - 2); }
friend ostream& operator<<(ostream& os, const mint& p){
return os << p.x;
}
friend istream& operator>>(istream& is, mint& p){
int64_t val;
is >> val;
p = mint(val);
return is;
}
};
template<typename T>
struct Combination{
int sz;
vector<T> fact_;
vector<T> ifact_;
vector<T> inv_;
Combination(int n = 1e+6) : sz(n) {
fact_.resize(sz + 1);
ifact_.resize(sz + 1);
inv_.resize(sz + 1);
fact_[0] = ifact_[sz] = inv_[0] = 1;
for(int i = 1; i <= sz; ++i) fact_[i] = fact_[i - 1] * i;
ifact_[sz] /= fact_[sz];
for(int i = sz; i > 0; --i) ifact_[i - 1] = ifact_[i] * i;
for(int i = 1; i <= sz; ++i) inv_[i] = ifact_[i] * fact_[i - 1];
}
inline T fact(int k) const {
if(k < 0 || k > sz) return 0;
return fact_[k];
}
inline T ifact(int k) const {
if(k < 0 || k > sz) return 0;
return ifact_[k];
}
inline T inv(int k) const {
if(k < 0 || k > sz) return 0;
return inv_[k];
}
T get_permutation(int n, int k){
if(n < 0 || k < 0 || n < k) return 0;
return fact(n) * ifact(n - k);
}
T get_combination(int n, int k){
if(n < 0 || k < 0 || n < k) return 0;
return fact(n) * ifact(k) * ifact(n - k);
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
Combination<mint> comb(M);
// dp[k] := n m k
// dp[0] = 0;
// dp[k] = mCk * k^n - dp[k-1]
vector<mint> dp(M + 1);
for(int k = 1; k <= M; ++k){
dp[k] = comb.get_combination(M, k) * mint(k).pow(N) - dp[k - 1];
}
cout << dp[M] << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0