No.1697 Deque House
タグ : / 解いたユーザー数 11
作問者 :
eSeF
/ テスター :
Problem Statement
A house is going to hold a party lasting $K$ days, and $N$ people have been invited. Initially, the $N$ people stand in a horizontal row inside the house, and the $i$-th person from the left $(1\le i\le N)$ is called person $i$.
Over the $K$ days of parties, the party on day $d$ $(1\le d\le K)$ is going to proceed as follows.
- Each person remaining in the house as of day $d$ independently chooses either "leave" or "not leave".
- Among the people who chose "leave", those who satisfy at least one of the following conditions exit the house. All the others stay in the house.
- There is no person to their right who chose "not leave".
- There is no person to their left who chose "not leave".
- At this point, all the people remaining in the house hold the party of day $d$.
Note that at no point during the parties does the relative order of the people in the house change.
Now, it would be very sad if a participant were left all alone partway through, or if everyone went home partway through despite preparations having been made for $K$ days. Therefore, the success level of the whole series of parties over the $K$ days is defined as follows.
- If the parties on all $K$ days were held with two or more people
- Let $D_i$ be the number of days out of the $K$ days on which person $i$ participated in the party. The success level is $\displaystyle\sum_{i=1}^{N}A_i^{D_i}$.
- If on one or more of the $K$ days the number of participants in the party became one or fewer
- The success level is $0$.
The way the parties over the $K$ days are held is determined by how the people choose "leave" or "not leave" on each day. For all possible ways of choosing, compute the success level of the resulting $K$ days of parties, and find the sum of these values modulo $998244353$.
Two ways of choosing are considered different if there exist integers $i$ and $d$ such that the choice made by person $i$ on day $d$ differs.
Note here that a person who has exited the house makes no further choices.
Input
$N\ \ K$ $A_1\ \ A_2\ \cdots \ A_N$[Constraints]
- $2\le N\le 10^5$
- $1\le K\le 14$
- $1\le A_i\lt 998244353$
- All inputs are integers.
Output
Output the answer modulo $\bmod{998244353}$.
Sample
Sample 1
Input
3 1 1 2 4
Output
25
The party is held for only one day.
Denoting a person who chose "not leave" by 'o' and a person who chose "leave" by 'x', the ways of choosing that give a positive success level are the following.
oooooxoxoxoo
The people staying in the house are (person 1, person 2, person 3), (person 1, person 2), (person 1, person 2, person 3), and (person 2, person 3), respectively, so the total success level is $(1^1+2^1+4^1)+(1^1+2^1+4^0)+(1^1+2^1+4^1)+(1^0+2^1+4^1)=7+4+7+7=25$.
Note that even a person who participated on 0 days can affect the success level.
Sample 2
Input
2 14 2997 92458
Output
660248434
Since there are only two people from the start, the success level is positive only when both of them keep partying for two weeks without leaving. The success level in this case is $2997^{14}+92458^{14} \equiv 660248434\pmod{998244353}$.
Sample 3
Input
5 7 662 60 70 15 1034
Output
156455438
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。