結果
| 問題 |
No.8053 2.5 色で色塗り
|
| コンテスト | |
| ユーザー |
minami
|
| 提出日時 | 2019-04-02 09:53:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 127 ms / 2,000 ms |
| コード長 | 3,026 bytes |
| コンパイル時間 | 1,624 ms |
| コンパイル使用メモリ | 172,348 KB |
| 実行使用メモリ | 100,992 KB |
| 最終ジャッジ日時 | 2024-11-28 20:41:13 |
| 合計ジャッジ時間 | 2,742 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif
//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }
template<int MOD>
struct ModInt {
static const int kMod = MOD;
unsigned x;
ModInt() :x(0) {}
ModInt(signed x_) { x_ %= MOD; if (x_ < 0)x_ += MOD; x = x_; }
ModInt(signed long long x_) { x_ %= MOD; if (x_ < 0)x_ += MOD; x = x_; }
int get()const { return (int)x; }
ModInt &operator+=(ModInt m) { if ((x += m.x) >= MOD)x -= MOD; return *this; }
ModInt &operator-=(ModInt m) { if ((x += MOD - m.x) >= MOD)x -= MOD; return *this; }
ModInt &operator*=(ModInt m) { x = (unsigned long long)x*m.x%MOD; return *this; }
ModInt &operator/=(ModInt m) { return *this *= m.inverse(); }
ModInt operator+(ModInt m)const { return ModInt(*this) += m; }
ModInt operator-(ModInt m)const { return ModInt(*this) -= m; }
ModInt operator*(ModInt m)const { return ModInt(*this) *= m; }
ModInt operator/(ModInt m)const { return ModInt(*this) /= m; }
ModInt operator-()const { return ModInt(MOD - x); }
bool operator==(ModInt m)const { return x == m.x; }
bool operator!=(ModInt m)const { return x != m.x; }
ModInt inverse()const {
signed a = x, b = MOD, u = 1, v = 0;
while (b) {
signed t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
if (u < 0)u += MOD;
return ModInt(u);
}
};
template<int MOD>
ostream &operator<<(ostream &os, const ModInt<MOD> &m) { return os << m.x; }
template<int MOD>
istream &operator>>(istream &is, ModInt<MOD> &m) { signed long long s; is >> s; m = ModInt<MOD>(s); return is; };
template<int MOD>
ModInt<MOD> pow(ModInt<MOD> a, unsigned long long k) {
ModInt<MOD> r = 1;
while (k) {
if (k & 1)r *= a;
a *= a;
k >>= 1;
}
return r;
}
using mint = ModInt<MOD>;
// スターリング数
// O(n^2)
// Verified:
// https://yukicoder.me/submissions/330289
vector<vector<mint>> stirlingNumbers(int n) {
vector<vector<mint>> S(n + 1, vector<mint>(n + 1, 0));
S[0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
S[i + 1][j] += S[i][j] * j;
S[i + 1][j + 1] += S[i][j];
}
}
return S;
}
// 完全2部グラフの彩色多項式
// O(n^2 + n lg m)
mint chromaticPolynomialOfCompleteBipartiteGraph(int n, int m, mint x) {
auto S = stirlingNumbers(n);
mint ret = 0;
mint a = x;
for (int k = 1; k <= n; k++) {
ret += S[n][k] * a * pow(x - k, m);
a *= x - k;
}
return ret;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M; cin >> N >> M;
cout << chromaticPolynomialOfCompleteBipartiteGraph(N, M, mint(5) / 2) << endl;
return 0;
}
minami