#P9919. 「RiOI-03」A Journey to the Moonlight

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

「RiOI-03」A Journey to the Moonlight

Background

(The picture is from a Phigros music illustration. Please contact for removal if there is any infringement.)

Link to the harder version

KDOI’s business has expanded to the Moon. However, the Internet speed on the Moon is very slow, so they need to solve the network speed problem.

KDOI’s staff have developed a new type of wireless LAN module, Wife (WIreless Fidelity Extend). Each module can connect to at most two users, and it can choose to provide 11 unit of bandwidth to one of the connected users. However, no matter how many modules provide bandwidth to the same user at the same time, the user’s total bandwidth is always 11.

The employees are very lazy, often delaying a PPT for a whole month. So they are also too lazy to label the Wife modules, meaning all modules are indistinguishable from each other. In addition, to save electricity, no two modules are allowed to have exactly the same set of users they serve.

Now there are nn users who purchased the service. When the Wife system officially starts, the router (Lu-you-qi) finds a problem: some users may have no broadband to use. Kaitou has no Wife modules in hand, so he can only grab one, sacrifice one user’s interests, and provide broadband to all users who have broadband in a certain order. However, the users without broadband are very demanding: as long as they are not provided broadband consecutively in their registration order, they will threaten the router to refund.

Kaitou has already forgotten their registration times, so he can only randomly choose a permutation of 1n1\sim n to decide the order of providing broadband. To minimize the number of attempts, he will adjust which users are connected by Wife. He wants to know the minimum expected number of attempts needed to calm the customers’ anger.

In particular, Wife has two models. Model 11 may choose to connect to only one user, while model 22 must connect to two different users. You need to compute the answers for both models separately.

Kaitou surely won’t will do it himself, so he asks you to compute the result ansians_i for all i[0,n]i\in[0,n]. Considering that you would be exhausted if you reported them one by one, the kind router will give you an array aa, and you only need to output ai×ansi\sum a_i\times ans_i.

Problem Description

Formal statement

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

  • Choose a matching, 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 subsegment in the permutation in increasing label order.
  • w(G)w(G) is the minimum expected number of operations among all matchings.

Call this bipartite graph GG kk-legal if and only if:

  • Every left-side vertex has degree between kk and 22.
  • For any two left-side vertices, the sets of their adjacent vertices are not identical.

Define f(k,x)f(k,x) as the sum of w(G)w(G) over all kk-legal bipartite graphs GG with xx right-side vertices, where left-side vertices are indistinguishable.

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

Input Format

The first line contains two positive integers nn and the Wife model kk.

The second line contains n+1n+1 non-negative integers 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 written as (x,y)(x,y).

Explanation of Sample 1

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

For n=2n=2, the possible bipartite graphs are (each left-side vertex is represented by the tuple of its adjacent vertices):

()()

(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\times 3+\dfrac22\times 4=12, so the output is 1×1+1×2+1×12=151\times 1+1\times 2+1\times 12=15.

Explanation of Sample 2

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 (each left-side vertex is represented by the tuple of its adjacent vertices):

()()

(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\times 3+\dfrac62\times 3+\dfrac66=34$.

Constraints

For 100%100\% of the testdata, 0n1.5×1040\le n\le 1.5\times 10^4, 1k21\le k\le 2, and 0ai<9982443530\le a_i<998244353.

This problem uses bundled testcases.

Subtask\text{Subtask} Score\text{Score} nn\le kk\ge Special property
00 55 11
11 1010 500500 22
22 2020 11 ai1i!a_i\equiv\dfrac1{i!}
33 1.5×1041.5\times 10^4 22
44 4545 11

Translated by ChatGPT 5