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

31906번 - Alea Iacta Est 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
10 초 1024 MB58222040.816%

문제

You play a game with multiple fair six-sided dice. Each die’s face displays a single symbol. The objective of the game is to roll the dice and create a valid word from the symbols on top of each die. If you cannot form a word, you may reroll the dice for another attempt.

Figure 1: Five dice making a valid word corresponding to Sample Input 1.

Suppose there are five dice: one of them contains letters A, B, C, D, E, and P (abbreviated as ABCDEP), and the other dice contain letters AEHOXU, AISOLR, ABCDEF, and ABCSCC. The first roll yields the following letters on the tops of respective dice: P, X, R, E, and S. As it is impossible to arrange these letters into a valid word, you decide to keep the P, S, and E, and reroll the other dice, in an attempt to make words like PARSE, PAUSE, PHASE, POISE, PROSE, PULSE, or PURSE. The two dice yield E and A, resulting in the following five letters: P, E, A, E, and S. You still cannot think of a valid word, so you decide to keep four letters and reroll only the last die, which has three sides with letter C. By doing so, there is a 50ドル\%$ chance that it will be possible to make a final valid word: PEACE, as shown in Figure 1.

When you roll a die, it lands on any one of its faces with equal probability. What is the expected number of rolls needed to make a valid word, assuming you use an optimal strategy?

입력

The first line of input contains two numbers $d$ and $w,ドル where $d$ (1ドル≤d≤6$) is the number of dice and $w$ (1ドル≤w≤2\cdot 10^5$) is the number of valid words in the dictionary. The following $d$ lines each have 6ドル$ symbols, one for each face of the die. The final $w$ lines contain $w$ distinct valid words in the dictionary. Every word has exactly $d$ symbols.

All symbols in the input are either uppercase letters (AZ) or digits (09).

출력

If it is possible to make a valid word, output the expected number of rolls needed to make a valid word when using an optimal strategy. Otherwise, output impossible. Your answer should have an absolute or relative error of at most 10ドル^{-6}$.

제한

예제 입력 1

5 8
ABCDEP
AEHOXU
AISOLR
ABCDEF
ABCSCC
PARSE
PAUSE
PHASE
POISE
PROSE
PULSE
PURSE
PEACE

예제 출력 1

9.677887141

예제 입력 2

2 1
AAAAAA
BBBBBB
AB

예제 출력 2

1.0

예제 입력 3

3 1
123456
123456
123456
666

예제 출력 3

10.555444555

예제 입력 4

2 1
ABCDEF
GHI234
AB

예제 출력 4

impossible

힌트

출처

ICPC > World Finals > ICPC World Finals 2023 K번

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

출처

대학교 대회

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

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