#P10286. 「RiOI-03」A Journey to the Moonlight(加强版)

    ID: 11696 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>洛谷原创二分图生成函数快速数论变换 NTT

「RiOI-03」A Journey to the Moonlight(加强版)

Background

Compared with P9919, this problem has a larger Constraints range.

Problem Description

For a bipartite graph GG with mm vertices on the right side, define its weight w(G)w(G) as follows:

  • Choose a matching scheme, and mark the first matched right-side vertex. If no such vertex exists, then mark the first unmatched right-side vertex.
  • Each time, randomly choose a permutation of 1,2,,m1,2,\cdots,m. Stop when the unmatched right-side vertices and the marked vertex appear as a contiguous segment in the permutation in increasing label order.
  • w(G)w(G) is the minimum value of the expected number of operations over all matching schemes.

Define this bipartite graph GG to be kk-valid if and only if:

  • The degree of every left-side vertex is between kk and 2\color{red}2.
  • There do not exist two different left-side vertices whose sets of adjacent vertices are identical.

Let f(k,x)f(k,x) be the sum of w(G)w(G) over all kk-valid bipartite graphs GG with xx right-side vertices, where left-side vertices are not distinguished.

Given n,k,a0nn,k,a_{0\sim n}, compute inaif(k,i)mod998244353\sum\limits^n_i a_i f(k,i) \bmod998244353.

Input Format

The first line contains two positive integers n,kn,k.

The second line contains n+1n+1 non-negative integers, representing a0na_{0\sim n}.

Output Format

Output one non-negative integer, the answer.

2 1
1 1 1
15
3 2
1 1 1 1
40
12 1
1 1 4 5 1 4 1 9 1 9 8 1 0
721168027

Hint

By convention, a left-side vertex connected to right-side vertices numbered x,yx,y is denoted as (x,y)(x,y).

[Sample 1 Explanation]

For n=0,1n=0,1, the answers are clearly 1,21,2.

For n=2n=2, the possible bipartite graphs are (represented by the tuple formed by the neighbors of each left-side vertex):

()()

(1),(2),(1,2)(1),(2),(1,2)

$\{(1),(2)\},\{(1,2),(2)\},\{(1,2),(1)\},\{(1,2),(1),(2)\}$

Graphs with the same expectation are grouped together. The answer is 21+21×3+22×4=12\dfrac21+\dfrac21\times3+\dfrac22\times4=12, so the output is 1×1+1×2+1×12=151\times1+1\times2+1\times12=15.

[Sample 2 Explanation]

For n=0,1,2n=0,1,2, the answers are 1,1,41,1,4.

For n=3n=3, the possible bipartite graphs are (represented by the tuple formed by the neighbors of each left-side vertex):

()()

(1,2),(1,3),(2,3)(1,2),(1,3),(2,3)

{(1,2),(1,3)},{(1,2),(2,3)},{(1,3),(2,3)}\{(1,2),(1,3)\},\{(1,2),(2,3)\},\{(1,3),(2,3)\}

{(1,2),(2,3),(1,3)}\{(1,2),(2,3),(1,3)\}

The answer is $\dfrac61+\dfrac61\times3+\dfrac62\times3+\dfrac66=34$.

[Constraints]

For 100%100\% of the testdata, 0n1050\le n\le10^5, 1k21\le k\le2, 0ai<9982443530\le a_i<998244353.

Translated by ChatGPT 5