A8241 | Domino
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Little Gennady was presented with a set of domino for his birthday. The set consists of $28$ different dominoes of size $2×1$ . Both halves of each domino contain one digit from $0$ to $6$ .
Gennady chose a checked field of size $n×m$ and put there rectangular chips of sizes $1×2$ and $2×1$ . Each chip fully occupies exactly two neighboring squares of the field. Those chips do not overlap but they can touch each other. Overall the field has exactly $28$ chips, equal to the number of dominoes in the set. Now Gennady wants to replace each chip with a domino so that a magic figure appeared as a result. Different chips should be replaced by different dominoes. Determine in what number of contests Gennady can win over at the given position of the chips. You are also required to find one of the possible ways of replacing chips with dominoes to win the next Codeforces round.
0-0 0-1 0-2 0-3 0-4 0-5 0-6<br></br>1-1 1-2 1-3 1-4 1-5 1-6<br></br>2-2 2-3 2-4 2-5 2-6<br></br>3-3 3-4 3-5 3-6<br></br>4-4 4-5 4-6<br></br>5-5 5-6<br></br>6-6<br></br>The figure that consists of $28$ dominoes is called magic, if it can be fully covered with $14$ non-intersecting squares of size $2×2$ so that each square contained four equal numbers. Every time Gennady assembles a magic figure, some magic properties of the set appear — he wins the next contest. Gennady noticed that he can't assemble a figure that has already been assembled, otherwise someone else wins the contest.Gennady chose a checked field of size $n×m$ and put there rectangular chips of sizes $1×2$ and $2×1$ . Each chip fully occupies exactly two neighboring squares of the field. Those chips do not overlap but they can touch each other. Overall the field has exactly $28$ chips, equal to the number of dominoes in the set. Now Gennady wants to replace each chip with a domino so that a magic figure appeared as a result. Different chips should be replaced by different dominoes. Determine in what number of contests Gennady can win over at the given position of the chips. You are also required to find one of the possible ways of replacing chips with dominoes to win the next Codeforces round.
输入格式
The first line contains two positive integers $n$ and $m$ ( $1<=n,m<=30$ ). Each of the following $n$ lines contains $m$ characters, which is the position of chips on the field. The dots stand for empty spaces, Latin letters from "a" to "z" and "A", "B" stand for the positions of the chips. There are exactly 28 chips on the field. The squares covered by the same chip are marked by the same letter, different chips are marked by different letters. It is guaranteed that the field's description is correct.
It is also guaranteed that at least one solution exists.
It is also guaranteed that at least one solution exists.
输出格式
Print on the first line the number of ways to replace chips with dominoes to get a magic figure. That is the total number of contests that can be won using this arrangement of the chips. Next $n$ lines containing $m$ characters each, should contain a field from dots and numbers from $0$ to $6$ — any of the possible solutions. All dominoes should be different.
输入输出样例
输入 #1
8 8 .aabbcc. .defghi. kdefghij klmnopqj .lmnopq. .rstuvw. xrstuvwy xzzAABBy
输出 #1
10080 .001122. .001122. 33440055 33440055 .225566. .225566. 66113344 66113344
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted