結果
問題 |
No.1035 Color Box
|
ユーザー |
![]() |
提出日時 | 2020-06-29 23:14:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 1,697 bytes |
コンパイル時間 | 1,944 ms |
コンパイル使用メモリ | 198,228 KB |
最終ジャッジ日時 | 2025-01-11 13:36:35 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h> #define M_PI 3.14159265358979323846 // pi using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<ll> VI; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> t3; typedef tuple<ll, ll, ll, ll> t4; typedef tuple<ll, ll, ll, ll, ll> t5; #define rep(a,n) for(ll a = 0;a < n;a++) #define repi(a,b,n) for(ll a = b;a < n;a++) using namespace std; static const ll INF = 1e15; const ll mod = 1000000007; 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; } 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; Factorial f(n); ll all = mpow(m, n); ll sub = 0; ll sign = 1; for (int i = 1; i < m; i++) { //i個以下の色で塗る集合 ll lower = mpow(m - i, n) * f.cmb(m, i) % mod; sub += sign * lower + mod; sub %= mod; sign *= -1; } cout << (all - sub + mod) % mod << endl; return 0; }