a177. pC Froggy and Froggo
Tags :
Accepted rate : 2人/2人 ( 100% ) [非即時]
評分方式:
Tolerant

最近更新 : 2020-12-21 18:26

Content

原題連結

The king of the frogs has two sons, Froggy and Froggo. He wants to divide his kingdom into two parts, one for Froggy and one for Froggo.

The kingdom of the frogs is a square of n × n grids, with Froggy’s castle at the top-left corner (1, 1) and Froggo’s castle at the bottom-right corner (n, n). Each grid cell has a value, and these values may be different.

The king wants to be fair, but he doesn’t want an over complicated partition. He needs your help to generate a partition satisfying the following restrictions:

• The boundary of the partition is a path.

• The boundary starts at the bottom-left corner of some grid cell lying on the bottom row or the leftmost column of the grid.

• The boundary ends at the top-right corner of some grid cell lying on the top row or the rightmost column of the grid.

• The boundary consists of only edges of grid cells.

• If we walk along the boundary from its start to its end, we only go either upward or right. Moreover, we can only make at most five turns.

• The sum of values belongs to Froggy equals the sum of values belongs to Froggo.

Please write a program to calculate the minimum turns of a boundary satisfying all restriction above. If the minimum number of turns is greater than 5, your program should simply output NO.

Input

The first line contains an integer T indicating the number of test cases. The first line of each testcase contains an integer n. The following n lines contain n integers each, the j th element in the i th line aij is the value of the grid cell lying on the intersection of the i th row and the j th column.

 
Output

If the minimum number of turns is at most five turns, output YES and the minimum number of turns. Otherwise, output NO.

Technical Specification

• 1 ≤ T ≤ 20

• 1 ≤ n ≤ 50

• 1 ≤ aij ≤ 104

• 1 ≤ i, j ≤ n

• The sum of all n is at most 50.

Sample Input #1
Sample Input 1
2
3
3 3 2
4 2 2
2 1 1
3
5 5 5
5 1 1
1 1 16

Sample Input 2
1
2
15 3
3 3
Sample Output #1
Sample Output 1
YES 3
YES 2

Sample Output 2
NO
測資資訊:
記憶體限制: 512 MB
公開 測資點#0 (6%): 2.0s , <1M
公開 測資點#1 (6%): 2.0s , <1K
公開 測資點#2 (6%): 2.0s , <1M
公開 測資點#3 (6%): 2.0s , <1M
公開 測資點#4 (6%): 2.0s , <1M
公開 測資點#5 (7%): 2.0s , <1M
公開 測資點#6 (7%): 2.0s , <1M
公開 測資點#7 (7%): 4.0s , <1M
公開 測資點#8 (7%): 2.0s , <1M
公開 測資點#9 (7%): 2.0s , <1M
公開 測資點#10 (7%): 2.0s , <1M
公開 測資點#11 (7%): 2.0s , <1M
公開 測資點#12 (7%): 2.0s , <1M
公開 測資點#13 (7%): 2.0s , <1M
公開 測資點#14 (7%): 2.0s , <1M
Hint :
Tags:
出處:
CPTC2020 [管理者: s710426(?0_o)//) ]


ID User Problem Subject Hit Post Date
沒有發現任何「解題報告」