結果

問題 No.1302 Random Tree Score
ユーザー Shun_PIShun_PI
提出日時 2020-11-27 23:59:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 565 ms / 3,000 ms
コード長 1,679 bytes
コンパイル時間 4,186 ms
コンパイル使用メモリ 237,300 KB
実行使用メモリ 16,616 KB
最終ジャッジ日時 2023-10-09 22:11:26
合計ジャッジ時間 9,491 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,772 KB
testcase_01 AC 6 ms
5,868 KB
testcase_02 AC 112 ms
8,368 KB
testcase_03 AC 260 ms
11,628 KB
testcase_04 AC 107 ms
8,240 KB
testcase_05 AC 565 ms
16,308 KB
testcase_06 AC 462 ms
16,152 KB
testcase_07 AC 104 ms
8,548 KB
testcase_08 AC 290 ms
12,280 KB
testcase_09 AC 448 ms
16,616 KB
testcase_10 AC 472 ms
13,628 KB
testcase_11 AC 102 ms
7,808 KB
testcase_12 AC 533 ms
15,372 KB
testcase_13 AC 5 ms
5,808 KB
testcase_14 AC 449 ms
16,444 KB
testcase_15 AC 518 ms
16,452 KB
testcase_16 AC 5 ms
5,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; }
template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; }
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
constexpr int MAX = 200100;
mint fact[MAX], finv[MAX], inv[MAX];
void cominit() {
  int m = mint::mod();
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  FOR(i, 2, MAX){
    fact[i] = fact[i-1] * i;
    inv[i] = m - inv[m%i] * (m/i);
    finv[i] = finv[i-1] * inv[i];
  }
}
mint ncr(int n, int r) {return fact[n]*finv[r]*finv[n-r];}
int main()
{
  int N;
  cin >> N;
  cominit();
  vector<vector<mint>> a(20, vector<mint>(N-1));
  REP(i, N-1) a[0][i] = ((mint)i+1) * finv[i];
  FOR(k, 1, 20) {
    vector<mint> tmp = convolution(a[k-1], a[k-1]);
    REP(i, N-1) a[k][i] = tmp[i];
  }
  vector<mint> b(N-1);
  b[0] = 1;
  REP(k, 20) if(N>>k&1) {
    vector<mint> tmp = convolution(b, a[k]);
    REP(i, N-1) b[i] = tmp[i];
  }
  mint ans = b[N-2] * fact[N-2] * ((mint)N).pow(N-2).inv();
  cout << ans.val() << endl;

}
0