#P6430. [COCI 2008/2009 #1] SKAKAVAC
[COCI 2008/2009 #1] SKAKAVAC
Description
The flower field is an square. Each flower has its own label. represents the label in row , column .
The grasshopper is currently at row , column .
The grasshopper decides to explore a new world, so it wants to jump onto as many flowers as possible while following the rules below.
To jump from to , it must satisfy one of the following conditions:
- and ,
- and ,
and also .
Compute the maximum number of flowers the grasshopper can visit.
Input Format
The first line contains a single integer .
The second line contains two integers and .
The next lines each contain integers, representing the array .
Output Format
Output one integer, the maximum number of flowers the grasshopper can visit.
4
1 1
1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7
4
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
Hint
Constraints
- For of the testdata, .
- For of the testdata, .
- For of the testdata, , , .
Notes
This problem is translated from T5 SKAKAVAC of Croatian Open Competition in Informatics 2008/2009 Contest #1.
Translated by ChatGPT 5
京公网安备 11011102002149号