Gacha 101

시간 제한2초메모리 제한1024 MB

요약
1부터 N까지 번호가 붙은 공을 무작위 순서로 꺼낼 때, 어떤 시점에서 뽑힌 번호 집합이 연속한 세 수 i, i+1, i+2를 모두 포함할 확률을 구한다.
난이도

어려움10점 중 8점

유형
확률, 조합론, 동적 계획법, 완전 탐색
정답자
아직 제출이 없습니다

문제

For each i=1,2,…,Ni = 1, 2, \dots, N, there are A_iA\_i balls with ii written on them. These are put into a box and mixed up. The string variable ss consists of initially NN “0”s. Balls are taken out of the box one by one (uniformly at random and independently). When a ball with ii written on it is drawn, the ii-th character of ss is changed to “1” (it remains unchanged if it was already “1”). Find the probability, modulo 998,244,353998\\,244\\,353, of having a point during this process that ss contains “101” as a contiguous substring.

입력

The input consists of a single test case of the following format.

NN

A_1A\_1 A_2A\_2 …\dots A_NA\_N

The first line consists of an integer NN between 11 and 200,000200\\,000, inclusive. The second line consists of NN positive integers A_1,A_2,…,A_NA\_1, A\_2, \dots , A\_N. For each ii (1≤i≤N1 \le i \le N), A_iA\_i represents the number of balls ii written. And they satisfy ∑_1≤i≤NA_i<998,244,353\sum\_{1 \le i \le N}{A\_i} < 998\\,244\\,353.

출력

Output in a line the probability modulo 998,244,353998\\,244\\,353.

힌트

  • How to find the probability modulo 998,244,353998\\,244\\,353
    • It can be proved that the sought probability is always a rational number. Additionally, the constraints of this problem guarantee that if the sought probability is represented as an irreducible fraction yx\frac{y}{x}, then xx is not divisible by 998,244,353998\\,244\\,353. Here, there is a unique 0≤z<998,244,3530 \le z < 998\\,244\\,353 such that y≡xz(mod998,244,353)y \equiv xz \pmod{998\\,244\\,353}, so report this zz.

예제2

  1. 예제 1

    입력
    3
    1 2 3
    
    예상 출력
    465847365
    
  2. 예제 2

    입력
    10
    3 1 4 1 5 9 2 6 5 3
    
    예상 출력
    488186016