Note: This is an approximate problem. There is no exact solution. You must find the most optimal solution. Please, take a look at the sample explanation to ensure that you understand the problem correctly.
Problem statement
You are given an integer matrix A of size N×N. You can start at any cell of the matrix. You can walk in four directions (left, right, up, and down). You can not visit the same cell twice. Here, B1,B2,…,Bk denote the values of cells of the path in order of bypass. The value of the path is equal to ∑ki=1Bi⋅i. Your task is to find the path with maximum value.
Input format
Output format
X (1≤X≤N⋅N) is the length of path that you found. The format of the output is as follows:
Verdict and scoring
Your score is equal to the sum of the values of all test cases. The value of each test is equal to the value of path that you found.
If at least one of the rules will be violated, then your value for this test will be 0.
Test generation plan
The length of optimal path is 9. The value of path will be 314:
A1,3⋅1+A1,2⋅2+A1,1⋅3+A2,1⋅4+A3,1⋅5+A3,2⋅6+A3,3⋅7+A2,3⋅8+A2,2⋅9=314.