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

19449번 - Experience is Worth It 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 256 MB117675.000%

문제

Pasha is playing the video game "DiaBro III". He is fighting against $n \cdot m$ monsters in this game. The monsters are arranged into $n$ rows of $m$ columns each. Rows are numbered with sequential integers from 1ドル$ to $n$ and columns --- with sequential integers from 1ドル$ to $m$.

Each monster has one of $k$ types. The $i$-th monster type is described by two integers $q_{i}$ and $g_{i}$: Pasha can kill a monster of $i$-th type only if amount of his experience is at least $q_{i},ドル and after killing each monster of this type --- Pasha will gain $g_{i}$ units of experience.

Pasha wants to choose a rectangle by fixing four integers $r_{1},ドル $r_{2},ドル $c_{1}$ and $c_{2}$ such that 1ドル \leq r_{1} \leq r_{2} \leq n$ and 1ドル \leq c_{1} \leq c_{2} \leq m$. Then Pasha starts to kill monsters in the chosen rectangle --- at cells $(r, c)$ such that $r_{1} \leq r \leq r_{2}$ and $c_{1} \leq c \leq c_{2}$. Initially, he has no experience at all. The rectangle is good if it is possible to kill all monsters inside the rectangle in some order without killing any monster which is not in the rectangle.

You are to write a program that will find the number of different good rectangles.

입력

The first line of input contains two integers $n$ and $m$ (1ドル \leq n, m \leq 200$) --- the number of rows and columns of monsters respectively.

Each of the following $n$ lines contains exactly $m$ lowercase Latin letters. The $j$-th character of $i$-th line denotes the type of monster with row number $i$ and column number $j$. Monsters of the same type are denoted with the same lowercase Latin letter.

The next line contain the only integer $k$ (1ドル \leq k \leq 26$) --- the number of monster types.

Each of the following $k$ lines contains the description of some monster type. The description of $i$-th monster type consists of character $l_{i}$ --- the lowercase Latin letter corresponding to this monster type --- and two integers $q_{i}$ and $g_{i}$ (0ドル \leq q_{i} \leq 10^{9}, 1 \leq g_{i} \leq 10^{9}$) --- the amount of experience required to kill a monster of this type and the amount of experience obtained after killing each monster of this type respectively. The values of $l_{i},ドル $q_{i}$ and $g_{i}$ are separated by single spaces.

It is guaranteed that there is no monster of type that is not described in the input.

출력

The only line of output should contain one integer --- the number of ways to choose values $r_{1},ドル $r_{2},ドル $c_{1}$ and $c_{2}$ to satisfy all the conditions given above.

제한

예제 입력 1

2 3
aba
baa
2
a 0 2
b 4 100

예제 출력 1

11

예제 입력 2

4 6
aaaaaa
abbaaa
aaacba
aaabba
3
a 0 1
b 3 2
c 12 5

예제 출력 2

128

힌트

There are 11ドル$ possible values of $r_{1},ドル $r_{2},ドル $c_{1}$ and $c_{2}$ in the first sample:

  1. $r_{1} = 1,~~~r_{2} = 1,~~~c_{1} = 1,~~~c_{2} = 1$;
  2. $r_{1} = 1,~~~r_{2} = 1,~~~c_{1} = 1,~~~c_{2} = 3$;
  3. $r_{1} = 1,~~~r_{2} = 1,~~~c_{1} = 3,~~~c_{2} = 3$;
  4. $r_{1} = 1,~~~r_{2} = 2,~~~c_{1} = 1,~~~c_{2} = 2$;
  5. $r_{1} = 1,~~~r_{2} = 2,~~~c_{1} = 1,~~~c_{2} = 3$;
  6. $r_{1} = 1,~~~r_{2} = 2,~~~c_{1} = 2,~~~c_{2} = 3$;
  7. $r_{1} = 1,~~~r_{2} = 2,~~~c_{1} = 3,~~~c_{2} = 3$;
  8. $r_{1} = 2,~~~r_{2} = 2,~~~c_{1} = 1,~~~c_{2} = 3$;
  9. $r_{1} = 2,~~~r_{2} = 2,~~~c_{1} = 2,~~~c_{2} = 2$;
  10. $r_{1} = 2,~~~r_{2} = 2,~~~c_{1} = 2,~~~c_{2} = 3$;
  11. $r_{1} = 2,~~~r_{2} = 2,~~~c_{1} = 3,~~~c_{2} = 3$.

출처

Camp > Petrozavodsk Programming Camp > Summer 2016 > Day 2: Pavel Khaustov Contest 2 E번

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

출처

대학교 대회

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

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