Logo
(追記) (追記ここまで)

33123번 - Narrower Passageway 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB24151470.000%

문제

You are a strategist of The ICPC Kingdom. You received an intel that there will be monster attacks on a narrow passageway near the kingdom. The narrow passageway can be represented as a grid with 2ドル$ rows (numbered from 1ドル$ to 2ドル$) and $N$ columns (numbered from 1ドル$ to $N$). Denote $(r, c)$ as the cell in row $r$ and column $c$. A soldier with a power of $P_{r,c}$ is assigned to protect $(r, c)$ every single day.

It is known that the passageway is very foggy. Within a day, each column in the passageway has a 50ドル\%$ chance of being covered in fog. If a column is covered in fog, the two soldiers assigned to that column are not deployed that day. Otherwise, the assigned soldiers will be deployed.

Define a connected area $[u, v]$ ($u ≤ v$) as a maximal set of consecutive columns from $u$ to $v$ (inclusive) such that each column in the set is not covered in fog. The following illustration is an example of connected areas. The grayed cells are cells covered in fog. There are 4ドル$ connected areas: $[1, 2],ドル $[4, 6],ドル $[9, 9],ドル and $[11, 11]$.

The strength of a connected area $[u, v]$ can be calculated as follows. Let $m_1$ and $m_2$ be the maximum power of the soldiers in the first and second rows of the connected area, respectively. Formally, $m_r = \max(P_{r,u}, P_{r,u+1}, \dots , P_{r,v})$ for $r \in \{1, 2\}$. If $m_1 = m_2,ドル then the strength is 0ドル$. Otherwise, the strength is $\min(m_1, m_2)$.

The total strength of the deployment is the sum of the strengths for all connected areas. Determine the expected total strength of the deployment on any single day.

입력

The first line consists of an integer $N$ (1ドル ≤ N ≤ 100,円 000$).

Each of the next two lines consists of $N$ integers $P_{r,c}$ (1ドル ≤ P_{r,c} ≤ 200,円 000$).

출력

Let $M = 998,円 244,円 353$. It can be shown that the expected total strength can be expressed as an irreducible fraction $\frac{x}{y}$ such that $x$ and $y$ are integers and $y \not\equiv 0 \pmod M$. Output an integer $k$ in a single line such that 0ドル ≤ k < M$ and $k \cdot y \equiv x \pmod M$.

제한

예제 입력 1

3
8 4 5
5 4 8

예제 출력 1

249561092

There are 8ドル$ possible scenarios for the passageway.

Each scenario is equally likely to happen. Therefore, the expected total strength is $(0 + 5 + 10 + 5 + 5 + 0 + 5 + 0)/8 = \frac{15} {4}$. Since 249ドル,円 561,円 092 · 4 \equiv 15 \pmod 998,円 244,円 353,ドル the output of this sample is 249ドル,円 561,円 092$.

예제 입력 2

5
10 20 5 8 5
5 20 7 5 8

예제 출력 2

811073541

The expected total strength is $\frac{67}{16}$.

힌트

출처

ICPC > Regionals > Asia Pacific > Indonesia > Jakarta > The 2024 ICPC Asia Jakarta Regional Contest E번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /