#732
Silver II
Hoof Paper Scissors Minus One
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Note: The time limit for this problem is 3s, 1.5x the default.

In a game of Hoof Paper Scissors, Bessie and Elsie can put out one of NN (1N30001 \leq N \leq 3000) different hoof symbols labeled 1N1\dots N, 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 MM (1M30001 \leq M \leq 3000) 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 (L,R)(L,R) where LL is the symbol the cow plays with her left hoof and RR 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 NN and MM representing the number of hoof symbols and the number of games that Bessie and Elsie play.

Out of the following NN lines of input, the iith line consists of ii characters ai,1ai,2ai,ia_{i,1}a_{i,2}\ldots a_{i,i} where each ai,j{D,W,L}a_{i,j} \in \{\texttt D,\texttt W,\texttt L\}. If ai,j=Da_{i,j} = \texttt D, then symbol ii draws against symbol jj. If ai,j=Wa_{i,j} = \texttt W, then symbol ii wins against symbol jj. If ai,j=La_{i,j} = \texttt L, then symbol ii loses against symbol jj. It is guaranteed that ai,i=Da_{i,i} = \texttt D.

The next MM lines contain two space separated integers s1s_1 and s2s_2 where 1s1,s2N1 \leq s_1,s_2 \leq N. This represents Elsie's symbol combination for that game.

출력

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

예제 입력 1

3 3
D
WD
LWD
1 2
2 3
1 1

예제 출력 1

0
0
5

점수

Inputs 2-6: N,M100N,M\le 100Inputs 7-12: No additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Silver II1명 투표· 약 1개월 전
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.