問題一覧 > 通常問題

No.309 Shy People (1)

レベル : / AI推定難易度 : 1975 / 実行時間制限 : 1ケース 4.000秒 / メモリ制限 : 512 MB / 小数誤差許容問題 絶対誤差または相対誤差が $10^{-8}$ 以下。ただし、ジャッジ側の都合で500桁未満にしてください
タグ : (AC するまで非表示) / 解いたユーザー数 34
作問者 : LayCurse
お気に入りにしたユーザー ProblemId : 846 / 自分の提出
問題文最終更新日: 2026-06-25 03:20:42
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
Advent Calendar Contest 2015 (順位表) の他の問題:

Note

This problem was created as the problem for day 2 of the Advent Calendar Contest Advent Calendar 2015.

Problem Statement

During a talk given by someone who wishes to remain anonymous, the speaker asked the audience to raise their hands if they knew which prefecture the city of Kurashiki is in, and an incident occurred in which only $3$ to $4$ tenths of the people raised their hands.
Speaking of Kurashiki, it has the Bikan Historical Quarter with its beautiful white walls, the Ohara Museum of Art, and Furuichi, famous for Kurashiki udon; Tivoli Park closed down and became a shopping mall.
In any case, it is a popular sightseeing spot, and it is also famous for a climate that makes it very pleasant to live in.
There is no way it could be this little known, but unfortunately the audience consisted of competitive programmers, many of whom were shy, so it is believed that they did not raise their hands even though they knew.

To verify this, let us experiment with a simple model.
Shy people are thought to find it hard to raise their hands if the people around them are not raising theirs, and this is a model of that psychology.
There are seats in $R$ rows and $C$ columns, and all the seats are filled with audience members.
The talk is given at the top, and the person in the $i$-th row from the top and the $j$-th column from the left is denoted by $(i,j)$.
The probability that person $(i,j)$ knows which prefecture the city of Kurashiki is in is $P_{i,j} / 100$, that is, $P_{i,j}\%$, and whether each person knows it is an independent event.
In addition, for each person $(i,j)$, a parameter $S_{i,j} \in \{0,1,2,3,4\}$ representing that person's shyness is given.

Whether an audience member raises their hand is determined by the following mechanism.
Initially, everyone has $0$ points, and a person raises their hand the moment their points become $4$ or more, and keeps it raised.
If person $(i,j)$ knows which prefecture the city of Kurashiki is in, that person gains $4-S_{i,j}$ points.
Each time one of the people in front $(i-1,j)$, to the left $(i,j-1)$, or to the right $(i,j+1)$ of person $(i,j)$ raises their hand, person $(i,j)$ gains $1$ point at that moment.
In other words, if the people in front, to the left, and to the right all raise their hands, a total of $3$ points are gained.
Note that if there is no person in front, to the left, or to the right, the corresponding points are not gained.

Write a program that finds the expected value of the number of people who eventually raise their hands.

Input

$R$ $C$

$P_{1,1}$ $P_{1,2}$ $\cdots$ $P_{1,C}$
$P_{2,1}$ $P_{2,2}$ $\cdots$ $P_{2,C}$
$\quad \vdots$
$P_{R,1}$ $P_{R,2}$ $\cdots$ $P_{R,C}$

$S_{1,1}$ $S_{1,2}$ $\cdots$ $S_{1,C}$
$S_{2,1}$ $S_{2,2}$ $\cdots$ $S_{2,C}$
$\quad \vdots$
$S_{R,1}$ $S_{R,2}$ $\cdots$ $S_{R,C}$

$1 \leq R, C \leq 11$
$0 \leq P_{i,j} \leq 100$, $P_{i,j} \in \mathbb{Z}$
$S_{i,j} \in \{0,1,2,3,4\}$

Output

Output the expected number of people who raise their hands on $1$ line.
Your answer is considered correct if the relative error or the absolute error is at most $10^{-8}$.

Sample

Sample 1
Input
1 2

50 50

1 0
Output
0.75

If $(1,1)$ knows and $(1,2)$ also knows, $(1,1)$ gains $4-1=3$ points and $(1,2)$ gains $4-0=4$ points.
Therefore, $(1,2)$ raises their hand, and $(1,1)$, seeing this, gains $1$ point, reaching a total of $4$ points, and so raises their hand.
If $(1,1)$ does not know and $(1,2)$ knows, only $(1,2)$ raises their hand.
If $(1,2)$ does not know, then regardless of $(1,1)$, neither of them raises their hand.
Each person knows with probability $1/2$, and the $4$ cases occur with equal probability, so the answer is $2 \times (1/4) + 1 \times (1/4) + 0 \times (1/4) + 0 \times (1/4) = 3/4$.

Sample 2
Input
2 2

50 50
50 50

0 1
2 0
Output
1.375

$(1,1)$ and $(2,2)$ each raise their hand if they know.
$(1,2)$ raises their hand if they know and $(1,1)$ raises their hand.
$(2,1)$ raises their hand if they know and both $(1,1)$ and $(2,2)$ raise their hands.
Therefore, the probability that $(1,1)$ and $(2,2)$ each raise their hand is $1/2$, the probability that $(1,2)$ raises their hand is $1/4$, and the probability that $(2,2)$ raises their hand is $1/8$.
By linearity of expectation, the answer is $1/2 + 1/2 + 1/4 + 1/8 = 1.375$.

Sample 3
Input
10 10

100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100

1 2 3 4 1 2 3 4 1 2
3 4 1 2 3 4 1 2 3 4
1 2 3 4 1 2 3 4 1 2
3 4 1 2 3 4 1 2 3 4
1 2 3 4 1 2 3 4 1 2
3 4 1 2 3 4 1 2 3 4
1 2 3 4 1 2 3 4 1 2
3 4 1 2 3 4 1 2 3 4
1 2 3 4 1 2 3 4 1 2
3 4 1 2 3 4 1 2 3 4
Output
0

Even though everyone knows...

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。