2064: [USACO 2025 US Open Contest, Bronze] Problem 1. Hoof Paper Scissors Minus One

文件提交:无需freopen 内存限制:256 MB 时间限制:16.000 S
评测方式:普通裁判 命题人:
提交:1 解决:1

题目描述

In a game of Hoof Paper Scissors, Bessie and Elsie can put out one of  () different hoof symbols labeled , each corresponding to a different material. There is a complicated chart of how the different materials interact with one another, and based on that chart, either:

  • One symbol wins and the other loses.
  • The symbols draw against each other.

Hoof Paper Scissors Minus One works similarly, except Bessie and Elsie can each put out two symbols, one with each hoof. After observing all four symbols that they have all put out, they each choose one of their two symbols to play. The outcome is decided based on normal Hoof Paper Scissor conventions.

Given the  () symbol combinations that Elsie plans to make across each game, Bessie wants to know how many different symbol combinations would result in a guaranteed win against Elsie. A symbol combination is defined as an ordered pair  where  is the symbol the cow plays with her left hoof and  is the symbol the cow plays with her right hoof. Can you compute this for each game?

输入

The first line contains two space-separated integers N and M representing the number of hoof symbols and the number of games that Bessie and Elsie play.

Out of the following  lines of input, the th line consists of  characters   where each . If , then symbol  draws against symbol . If , then symbol  wins against symbol . If , then symbol  loses against symbol . It is guaranteed that .

The next  lines contain two space separated integers  and  where . This represents Elsie's symbol combination for that game.

输出

Output M lines where the i-th line contains the number of symbol combinations guaranteeing that Bessie can beat Elsie in the i-th game.

样例输入

3 3
D
WD
LWD
1 2
2 3
1 1

样例输出

0
0
5

提示

In this example, this corresponds to the original Hoof Paper Scissors and we can let Hoof = 1, Paper = 2, and Scissors = 3. Paper beats Hoof, Hoof beats Scissors, and Scissors beats Paper. There is no way for Bessie to guarantee a win against the combinations of Hoof + Paper or Paper + Scissors. However, if Elsie plays Hoof + Hoof, Bessie can counteract with any of the following combinations.
  • Paper+Paper
  • Paper+Scissors
  • Paper+Hoof
  • Hoof+Paper
  • Scissors+Paper

If Bessie plays any of these combinations, she can guarantee that she wins by putting forward Paper.

SCORING:

  • Inputs 2-6: 
  • Inputs 7-12: No additional constraints.

来源/分类