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

28048번 - Italian Calzone & Pasta Corner 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3.5 초 (추가 시간 없음) 1024 MB157776352.066%

문제

The Italian Calzone & Pasta Corner restaurant designed its menu having its dishes in a $R \times C$ two-dimensional grid, keeping dishes that go well together nearby each other. To eat, you choose a starting cell, and then repeatedly move up, down, left, or right to any of the four adjacent cells, getting any dishes you move through. Moving into already visited cells is allowed, but you don’t get the same dish again.

One day, Pierre, a foreign customer, showed up really hungry, and with a very strict etiquette background. He has a very specific order in which the dishes must be eaten. For example an appetizer, then an entree, then a main dish, then a salad, etc. So he assigned a distinct integer from 1ドル$ to $R \times C$ to each dish in the menu grid, indicating the order in which he would eat the whole menu. Now he wants to choose and eat dishes following his order. Since the restaurant’s rules might prevent him from choosing the whole menu, he is fine with skipping some of the steps given by his order. Can you help him choose a meal with as many dishes as possible?

입력

The first line contains two integers $R$ and $C$ (1ドル ≤ R, C ≤ 100$), indicating that the menu grid has $R$ rows and $C$ columns. The next $R$ lines contain $C$ integers each, representing the menu grid. Each of these numbers is a distinct integer from 1ドル$ to $R \times C$ assigned by Pierre to the corresponding dish in the menu grid.

출력

Output a single line with an integer indicating the maximum amount of dishes that Pierre can eat.

제한

예제 입력 1

1 5
5 3 2 1 4

예제 출력 1

5

예제 입력 2

1 5
1 5 4 3 2

예제 출력 2

4

예제 입력 3

3 3
4 1 3
8 5 9
7 2 6

예제 출력 3

6

힌트

출처

ICPC > Regionals > Latin America > Latin America Regional Contests > Latin America Regional Contests 2022 I번

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

출처

대학교 대회

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

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