RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00077

Skakavac

Platinum III 플래티넘 III
난이도
4s
시간 제한
35MB
메모리 제한
0
맞았습니다!!
1
제출 수
0.0%
정답률
레이팅

의견: 0

설명

A grasshopper is in a flower field. The field contains \(N \cdot N\) flowers arranged in \(N\) rows and \(N\) columns. For each flower in the field, we know how many petals it has.

The grasshopper is initially on the flower in row \(R\) and column \(C\). Its goal is to visit as many flowers as possible while obeying these rules:

  1. It can only jump into an adjacent row or column. If it jumps into the adjacent row, it must jump at least two columns, and if it jumps into the adjacent column, it must jump at least two rows. In other words, it can jump from flower \((r_1, c_1)\) to flower \((r_2, c_2)\) if:
    • \(|r_1 - r_2| = 1\) and \(|c_1 - c_2| > 1\), or
    • \(|c_1 - c_2| = 1\) and \(|r_1 - r_2| > 1\)
  2. The number of petals on the next flower must be strictly larger than the number of petals on the previous flower.

Write a program that calculates the largest number of flowers the grasshopper can visit.

제약
입력 형식

The first line contains the integer \(N\) (\(1 \le N \le 1500\)), the size of the field.

The second line contains integers \(R\) (\(1 \le R \le N\)) and \(C\) (\(1 \le C \le N\)), the grasshopper's initial position.

The next \(N\) lines contain \(N\) positive integers separated by spaces, each less than \(1\,000\,000\), the numbers of petals on the flowers.

출력 형식

Output a single integer – the largest number of flowers the grasshopper can visit.

Scoring: In test data worth \(50\%\) of points, \(N\) will be at most \(100\). In test data worth \(80\%\) of points, \(N\) will be at most \(1000\).

서브태스크
서브태스크점수설명

Subtask 1

60점

\(N \le 100\)

Subtask 2

36점

\(N \le 1000\)

Subtask 3

24점

No additional constraints (\(N \le 1500\)).

예제 1
입력
4
1 1
1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7
출력
4
예제 2
입력
5
3 3
20 16 25 17 12
11 13 13 30 17
15 29 10 26 11
27 19 14 24 22
23 21 28 18 13
출력
21
문제 정보

riseoj 작성

출처 COCI 2008/2009 Contest 1

평가 및 의견

Skakavac

개요
출제자 난이도 Platinum III 플래티넘 III 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Skakavac

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8