#P16564. [ICPC 2026 APC] Minesweeper String
[ICPC 2026 APC] Minesweeper String
题目描述
You are given a string of length consisting of digits 0–9. You want to use this string to generate a variant of Minesweeper. In this variant, a cell may contain more than one mine, and the mine count in a cell is based on its 4-neighborhood (edge-adjacent cells), instead of the usual 8-neighborhood.
To do that, you choose an integer ( ) representing the width of the grid. You arrange the cells, numbered from to , into a grid. The grid has rows numbered from to from top to bottom, and columns numbered from to from left to right. For each , cell is located at row and column , and corresponds to the -th digit of . Thus, row contains cells to , row contains cells to , and so on. Note that the bottommost row may contain less than cells.
After arranging the grid, you perform the following steps:
- For each cell corresponding to a non-zero digit (1–9), you place mines in that cell.
- For each remaining cell corresponding to 0, you write a number in that cell that is equal to the total number of mines in its adjacent cells. Two cells are adjacent if they share an edge. Note that each cell has at most four adjacent cells.
For a width , define as the sum of the numbers in all cells without mines on the generated grid. Given an integer , your task is to compute the -th largest value among the values .
输入格式
The first line of input contains two integers and ( ).
The second line contains a string of length consisting of digits 0–9.
输出格式
Output the -th largest value among .
5 3
20103
7
5 1
20103
11
8 4
60409003
35
提示
Explanation for the sample input/output #1
Figure F.1 illustrates the resulting grids for widths to . Each dot in a cell represents one mine.
Figure F.1: The resulting grids for all possible widths.By summing up the numbers on the cells containing no mines, you obtain the following.
The third largest value among them is .