結果
| 問題 |
No.1302 Random Tree Score
|
| ユーザー |
kyort0n
|
| 提出日時 | 2020-11-28 01:25:30 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 493 ms / 3,000 ms |
| コード長 | 1,583 bytes |
| コンパイル時間 | 3,384 ms |
| コンパイル使用メモリ | 209,476 KB |
| 実行使用メモリ | 11,172 KB |
| 最終ジャッジ日時 | 2024-09-12 21:38:37 |
| 合計ジャッジ時間 | 7,837 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/convolution>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template<class T>
inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
const long long INF = 1e18;
const ll mod = 998244353;
using mint = atcoder::modint998244353;
ll N;
mint Factorial[105000];
vector<mint> mul(vector<mint> a, vector<mint> b) {
vector<mint> ret = atcoder::convolution(a, b);
ret.resize(N - 1);
return ret;
}
vector<mint> power(vector<mint> v, ll x) {
vector<mint> ret;
ret.push_back(1);
vector<mint> factor = v;
ll idx = 0;
while(x) {
if(x & (1LL << idx)) {
ret = mul(ret, factor);
x -= (1LL << idx);
}
factor = mul(factor, factor);
idx++;
}
return ret;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
Factorial[0] = 1;
cin >> N;
for(ll i = 1; i <= N; i++) {
Factorial[i] = Factorial[i-1] * i;
//cerr << i << " " << Factorial[i].val() << endl;
}
vector<mint> v;
for(int i = 0; i <= N - 2; i++) {
v.push_back((i + 1) / Factorial[i]);
}
auto u = power(v, N);
mint ans = u[N-2];
ans *= Factorial[N-2];
mint factor = 1;
for(int i = 0; i < N - 2; i++) factor *= N;
ans /= factor;
cout << ans.val() << endl;
return 0;
}
kyort0n