問題一覧 > 通常問題

No.662 Slot Machine

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 小数誤差許容問題 絶対誤差または相対誤差が $10^{-1}$ 以下。ただし、ジャッジ側の都合で500桁未満にしてください
タグ : (AC するまで非表示) / 解いたユーザー数 138
作問者 : horiesiniti / テスター : ciel
お気に入りにしたユーザー ProblemId : 2090 / 自分の提出
問題文最終更新日: 2026-06-26 05:47:18
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. Show the original
yukicoder contest 186 (順位表) の他の問題:

Note

This problem was originally published on HackerRank and is published here with the permission of both yukicoder and HackerRank.

Problem Statement

You are a developer of slot machines.

This slot machine has 5 kinds of symbols and is an ordinary slot machine with 3 columns * 3 rows, where pressing a button stops each column. Naturally, as usual, coins are paid out when three matching symbols line up on one of the 3 horizontal rows or one of the 2 diagonals.

You have been assigned two tasks.

The first task is to find the expected value of the number of coins the slot machine returns to the customer in one game, assuming that for every column, each position at which the reel can stop is equally likely. (An error of up to 0.1 is allowed.)

The second task is to consider all possible ways the reels can stop and to calculate, for each symbol, a simple total over all cases of how many times that symbol lines up. (If this explanation is hard to understand, infer the meaning from the sample input.)

Write a program that computes these two tasks from the given data.

If multiple lines match at the same time, the player receives the total of the respective payouts.

Input

$str_1$ $coin_1$
$str_2$ $coin_2$
$str_3$ $coin_3$
$str_4$ $coin_4$
$str_5$ $coin_5$
$n_1$
$A_1$
$\dots$
$A_{n_1}$
$n_2$
$B_1$
$\dots$
$B_{n_2}$
$n_3$
$C_1$
$\dots$
$C_{n_3}$

$str_i$ $coin_i$ are the name of a symbol and the number of coins returned when that symbol lines up.

$n_1$ is the length of the reel in the 1st column, and $A_{ni}$ is the name representing the symbol at position i of the reel in the 1st column.

$n_2$ is the length of the reel in the 2nd column, and $B_{ni}$ is the name representing the symbol at position i of the reel in the 2nd column.

$n_3$ is the length of the reel in the 3rd column, and $C_{ni}$ is the name representing the symbol at position i of the reel in the 3rd column.

The symbol names in $n_i$ are each included among the $str_j$.

$3\le n_1 ,n_2 ,n_3\le5000$

Symbol names consist of 1 to 10 half-width alphanumeric characters (uppercase and lowercase), and the number of coins $coin_i$ is a natural number not exceeding 1001.

Output

$a$
$U_1$
$U_2$
$U_3$
$U_4$
$U_5$

a is the expected number of coins returned when the reels are spun once (the number of coins inserted need not be considered).

$U_i$ is the simple total of how many times the symbol $str_i$ lines up when all possible ways of stopping the reels are tried. Output these values.

Sample

Sample 1
Input
Bell 5
star 10
heart 20
spade 50
diamond 100
6
Bell
diamond
star
spade
star
Bell
6
Bell
heart
star
Bell
heart
diamond
6
spade
heart
spade
star
Bell
diamond
Output
3.240741
20
10
0
0
5

The expected number of coins returned when the slot machine is spun once is 3.240741.

When all ways of stopping the slot machine are tried, Bell lines up 20 times, star 10 times, heart 0 times, spade 0 times, and diamond 5 times.

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