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

5991번 - Papaya Jungle 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB1631049061.644%

문제

Bessie has wandered off the farm into the adjoining farmer's land. He raises delicious papaya fruit, which is a delicacy for cows. The papaya jungle is partitioned into a grid of squares with R rows and C columns (1 <= R <= 40, 1 <= C <= 40), as is popular in Wisconsin. Bessie can travel from a given square to any existing adjacent square whose route is parallel to the X or Y axis. So in the following diagram, if Bessie is at the square labeled "B", she can travel to any of the squares labeled "T":

 .T.
 TBT
 .T.

Bessie always starts out by munching the papayas in square (row=1,col=1). After she's done with one square, Bessie always uses her trusty binoculars to count the low-hanging fruit in each of the adjacent squares. She then always moves to the square with the most visible uneaten fruit (a square that happily is always unique).

Sooner or later, following this rule, Bessie always ends up in square (R,C) and eats the fruit there.

Given the dimensions of the papaya jungle and the amount of fruit F_ij in each square (1 <= F_ij <= 100), determine the total number of fruit Bessie consumes for a given papaya jungle.

입력

  • Line 1: Two space-separated integers: R and C
  • Lines 2..R+1: Line i+1 describes row i of the jungle with C space-separated integers that tell how many fruit are in each square: F_i1, F_i2, ..., F_iC

출력

  • Line 1: A single integer that is the total number of papayas that Bessie eats by the time she finishes off the papayas at the barn in the lower right corner at coordinate (R,C).

제한

예제 입력 1

3 4
3 3 4 5
4 5 3 2
1 7 4 2

예제 출력 1

39

힌트

Bessie eats the papayas in the order given by the letters next to the numbers below:

 (1,1) ---> (1,C)
(1,1) 3a 3 4g 5h (1,C)
 | 4b 5c 3f 2i |
(R,1) 1 7d 4e 2j (R,C)
 (R,1) ---> (R,C)

She declines to eat 4 of the papayas but consumes 39 (visiting all but two squares of the grid).

출처

Olympiad > USA Computing Olympiad > 2009-2010 Season > USACO October 2009 Contest > Gold 4번

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

출처

대학교 대회

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

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