#P1074. [NOIP 2009 提高组] 靶形数独

    ID: 74 远端评测题 1000ms 125MiB 尝试: 1 已通过: 1 难度: 7 上传者: 标签>搜索2009NOIp 提高组剪枝位运算,按位

[NOIP 2009 提高组] 靶形数独

Description

Xiaocheng and Xiaohua are both good students who love mathematics. Recently, they have both become fascinated with Sudoku. Competitive as they are, they want to use Sudoku to compete. However, ordinary Sudoku is too easy for them, so they consulted Dr. Z, who brought out his recently invented “Target Sudoku” as their challenge.

The grid of Target Sudoku is the same as ordinary Sudoku: in a 9×99 \times 9 large grid there are 99 small 3×33 \times 3 subgrids (separated by bold black lines). In this large grid, some numbers are already given. Based on these numbers, use logical reasoning to fill the empty cells with digits 11 to 99. Each digit cannot repeat within any small 3×33 \times 3 subgrid, and cannot repeat within any row or column. Target Sudoku differs from ordinary Sudoku in one respect: each cell has a score, and like a target, the closer it is to the center, the higher the score (see figure).

The specific score distribution is: the innermost single cell (yellow region) is worth 1010 points; the ring outside the yellow region (red region) is 99 points per cell; the next ring (blue region) is 88 points per cell; the ring outside the blue region (brown region) is 77 points per cell; and the outermost ring (white region) is 66 points per cell, as shown above. The task is: each person must complete a given Sudoku (each given Sudoku may have multiple valid completions), and strive for the highest total score. The total score is the sum, over all cells, of the product of the cell’s score and the digit filled in that cell when the Sudoku is completed.

As shown below, in this completed Target Sudoku, the total score is 28292829. The game rules determine the winner by comparing total scores.

Eager to win, Xiaocheng turns to you, a skilled programmer, to compute the highest possible total score for a given Target Sudoku.

Input Format

There are 99 lines in total. Each line contains 99 integers (each between 00 and 99 inclusive), representing a partially filled Sudoku grid. Unfilled cells are represented by 00. Each pair of integers is separated by a single space.

Output Format

Output a single line: the maximum total score achievable for the given Target Sudoku. If the Sudoku has no solution, output 1-1.

7 0 0 9 0 0 0 0 1 
1 0 0 0 0 5 9 0 0 
0 0 0 2 0 0 0 8 0 
0 0 5 0 2 0 0 0 3 
0 0 0 0 0 0 6 4 8 
4 1 3 0 0 0 0 0 0 
0 0 7 0 0 2 0 9 0 
2 0 1 0 6 0 8 0 4 
0 8 0 5 0 4 0 1 2

2829
0 0 0 7 0 2 4 5 3 
9 0 0 0 0 8 0 0 0 
7 4 0 0 0 5 0 1 0 
1 9 5 0 8 0 0 0 0 
0 7 0 0 0 0 0 2 5 
0 3 0 5 7 9 1 0 8 
0 0 0 6 0 1 0 0 0 
0 6 0 9 0 0 0 0 1 
0 0 0 0 0 0 0 0 6
2852

Hint

  • Constraints:
    • For 40%40\% of the testdata, the number of non-zero entries in the Sudoku is at least 3030.
    • For 80%80\% of the testdata, the number of non-zero entries in the Sudoku is at least 2626.
    • For 100%100\% of the testdata, the number of non-zero entries in the Sudoku is at least 2424.

NOIP 2009 Senior, Problem 3.

Translated by ChatGPT 5