AtCoder Regular Contest 214
A
相同和的网格路径
Same Sum Grid Path
AtCoder
⌀ 442
原题
←B →

相同和的网格路径AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

There is an $N \times N$ grid. Let $(i,j)$ denote the cell at the $i$-th row from the top and $j$-th column from the left.

有一个 $N \times N$ 的网格。记从上往下第 $i$ 行、从左往右第 $j$ 列的单元格为 $(i,j)$。AI (CI翻译)

You are given $N \times N$ characters $S_{1,1}, \dots , S_{N,N}$. Each character is a digit (0 to 9) or ?. Determine if it is possible to replace each ? with a digit to satisfy the following condition, and if possible, output one such way of replacement.

给定 $N \times N$ 个字符 $S_{1,1}, \dots , S_{N,N}$。每个字符是一个数字(0 到 9)或 ?。请判断是否可以将每个 ? 替换为一个数字,使其满足以下条件;如果可以,请输出一种替换方案。AI (CI翻译)

For each $1 \le i,j \le N$, write $S_{i,j}$ as an integer in cell $(i,j)$. For a path from cell $(1,1)$ to cell $(N,N)$ by repeating moves only to adjacent cells to the right or down, let the score of the path be the sum of the integers written in the cells on the path (including the start and end points). Then, for all $\binom{2N-2}{N-1}$ possible paths, the scores are all equal.

对于每个 $1 \le i,j \le N$,将 $S_{i,j}$ 作为整数写入单元格 $(i,j)$。

对于一条从单元格 $(1,1)$ 出发,通过反复向右或向下移动到相邻单元格,最终到达单元格 $(N,N)$ 的路径,定义该路径的得分为路径上所有单元格中所写整数之和(包括起点和终点)。

对于全部 $\binom{2N-2}{N-1}$ 条可能的路径,它们的得分必须全部相等。

AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $2 \le N \le 100$
  • $S_{i,j}$ is a digit (0 to 9) or ?.
  • $2 \le N \le 100$
  • $S_{i,j}$ 是一个数字(0 到 9)或 ?。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入通过标准输入给出,格式如下:AI (CI翻译)

N
S_{1,1}S_{1,2}\ldotsS_{1,N}
S_{2,1}S_{2,2}\ldotsS_{2,N}
\vdots
S_{N,1}S_{N,2}\ldotsS_{N,N}

N
S_{1,1}S_{1,2}\ldotsS_{1,N}
S_{2,1}S_{2,2}\ldotsS_{2,N}
\vdots
S_{N,1}S_{N,2}\ldotsS_{N,N}
AI (CI翻译)

Output

输出格式

AI (CI翻译)

If it is impossible to make a replacement that satisfies the condition, output -1. If possible, output $S_{1,1}, \dots , S_{N,N}$ after the replacement in the following format:

如果无法进行满足条件的替换,输出 -1。如果可以,请按照以下格式输出替换后的 $S_{1,1}, \dots , S_{N,N}$:AI (CI翻译)

S_{1,1}S_{1,2}\ldotsS_{1,N}
S_{2,1}S_{2,2}\ldotsS_{2,N}
\vdots
S_{N,1}S_{N,2}\ldotsS_{N,N}

S_{1,1}S_{1,2}\ldotsS_{1,N}
S_{2,1}S_{2,2}\ldotsS_{2,N}
\vdots
S_{N,1}S_{N,2}\ldotsS_{N,N}
AI (CI翻译)

If there are multiple solutions, any of them will be accepted.

如果有多个解,输出其中任意一个即可。AI (CI翻译)

样例

Input #1
3
101
0??
1??
Output #1
101
010
101
It is possible to replace `?` with digits so that the scores of all paths are $3$.
Input #2
4
2026
?2?8
????
?214
Output #2
-1
No replacement can satisfy the condition.
Input #3
2
99
99
Output #3
99
99
题目信息
题号
arc214_a
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。