結果
問題 | No.1302 Random Tree Score |
ユーザー | Mister |
提出日時 | 2020-11-27 22:33:53 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 23 ms / 3,000 ms |
コード長 | 1,512 bytes |
コンパイル時間 | 2,054 ms |
コンパイル使用メモリ | 117,336 KB |
実行使用メモリ | 7,904 KB |
最終ジャッジ日時 | 2023-10-09 20:35:48 |
合計ジャッジ時間 | 3,119 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
4,460 KB |
testcase_01 | AC | 4 ms
4,380 KB |
testcase_02 | AC | 9 ms
5,680 KB |
testcase_03 | AC | 13 ms
6,236 KB |
testcase_04 | AC | 8 ms
5,544 KB |
testcase_05 | AC | 22 ms
7,568 KB |
testcase_06 | AC | 22 ms
7,712 KB |
testcase_07 | AC | 9 ms
5,656 KB |
testcase_08 | AC | 14 ms
6,488 KB |
testcase_09 | AC | 23 ms
7,620 KB |
testcase_10 | AC | 22 ms
7,400 KB |
testcase_11 | AC | 8 ms
5,560 KB |
testcase_12 | AC | 22 ms
7,448 KB |
testcase_13 | AC | 4 ms
4,604 KB |
testcase_14 | AC | 22 ms
7,620 KB |
testcase_15 | AC | 22 ms
7,904 KB |
testcase_16 | AC | 4 ms
4,604 KB |
ソースコード
#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Number/combination.hpp" #include <vector> template <class T> struct Combination { int max_n; std::vector<T> f, invf; explicit Combination(int n) : max_n(n), f(n + 1), invf(n + 1) { f[0] = 1; for (int i = 1; i <= n; ++i) { f[i] = f[i - 1] * i; } invf[max_n] = f[max_n].inv(); for (int i = max_n - 1; i >= 0; --i) { invf[i] = invf[i + 1] * (i + 1); } } T fact(int n) const { return n < 0 ? T(0) : f[n]; } T invfact(int n) const { return n < 0 ? T(0) : invf[n]; } T perm(int a, int b) const { return a < b || b < 0 ? T(0) : f[a] * invf[a - b]; } T binom(int a, int b) const { return a < b || b < 0 ? T(0) : f[a] * invf[a - b] * invf[b]; } }; #line 2 "main.cpp" #include <atcoder/modint> #include <atcoder/convolution> #include <iostream> #line 6 "main.cpp" using namespace std; using mint = atcoder::modint998244353; const Combination<mint> C(200000); void solve() { int n; cin >> n; vector<mint> binom(n + 1), expo(n + 1); mint p = 1; for (int k = 0; k <= n; ++k) { binom[k] = C.binom(n, k); expo[k] = p * C.invfact(k); p *= n; } auto f = atcoder::convolution(binom, expo); cout << (f[n - 2] * C.fact(n - 2) / mint(n).pow(n - 2)).val() << "\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }