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

32856번 - Office Building 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB49372781.818%

문제

Company Z has purchased a land lot for their new office building. The land is shaped like a rectangular grid with $r$ rows and $c$ columns, in which each cell has a tree. The age of each tree is known.

Because Company Z is at the innovative front of the world, their new office building will not just be rectangular. Instead, it will have some exotic shape and a very special floor plan. The shape can be represented by some connected grid cells. There is no particular facing requirement of the building, and the floor plan can be rotated by 90ドル$ degrees an arbitrary number of times. However, the floor plan cannot be flipped vertically or horizontally.

Company Z wants to choose a building location within their land lot. The trees in those cells that are occupied by the building will have to be cut down. Company Z would like to preserve the trees so that the sum of age of the remaining trees is as large as possible. Could you help them choose the best location for their new office building?

입력

The first line of input contains two integers $r$ and $c$ (1ドル ≤ r, c ≤ 20$), the dimensions of the land lot.

The next $r$ lines each contain $c$ integers between 1ドル$ and 100ドル$ (both inclusive) describing the ages of the trees in the land lot.

The next line contains two integer $s$ and $t$ (1ドル ≤ s ≤ r,ドル 1ドル ≤ t ≤ c$), the dimensions of the floor plan.

The next $s$ lines each contain $t$ characters that describe the floor plan of the building. A hash (#) denotes a cell occupied by the building and a dot (.) denotes a non-occupied cell. There is at least one hash. It is guaranteed that the hashes form a connected shape. Two hashes are directly connected if their cells share a side, and a shape is connected when all its hashes are either directly or indirectly connected. There is no row or column in the floor plan that is completely empty.

출력

Output a single integer, the maximum sum of age of the trees that can be preserved.

제한

예제 입력 1

4 5
4 3 1 1 1
5 4 3 5 1
9 6 2 1 1
8 7 1 1 2
3 4
###.
#.##
#..#

예제 출력 1

58

예제 입력 2

3 3
6 6 6
3 6 1
1 1 1
2 3
#..
###

예제 출력 2

25

힌트

출처

ICPC > Regionals > North America > Southeast USA Regional > 2024 Southeast USA Regional Programming Contest > Division 2 F번

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

출처

대학교 대회

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

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