A9054 | Color the Carpet
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Even polar bears feel cold when lying on the ice. Therefore, a polar bear Alice is going to make a carpet. The carpet can be viewed as a grid with height $h$ and width $w$ . Then the grid is divided into $h×w$ squares. Alice is going to assign one of $k$ different colors to each square. The colors are numbered from 1 to $k$ . She may choose not to use all of the colors.
However, there are some restrictions. For every two adjacent squares (squares that shares an edge) $x$ and $y$ , there is a color constraint in one of the forms:
- $color(x)=color(y)$ , or
- $color(x)≠color(y)$ .
Example of the color constraints:
Ideally, Alice wants to satisfy all color constraints. But again, life in the Arctic is hard. It is not always possible to satisfy all color constraints. Fortunately, she will still be happy if at least  of the color constraints are satisfied.
If she has $4$ colors she can color the carpet in the following way:
And she is happy because  of the color constraints are satisfied, and . Your task is to help her color the carpet.
However, there are some restrictions. For every two adjacent squares (squares that shares an edge) $x$ and $y$ , there is a color constraint in one of the forms:
- $color(x)=color(y)$ , or
- $color(x)≠color(y)$ .
Example of the color constraints:
Ideally, Alice wants to satisfy all color constraints. But again, life in the Arctic is hard. It is not always possible to satisfy all color constraints. Fortunately, she will still be happy if at least  of the color constraints are satisfied.
If she has $4$ colors she can color the carpet in the following way:
And she is happy because  of the color constraints are satisfied, and . Your task is to help her color the carpet.
输入格式
The first line contains three integers $h,w,k$ $(2<=h,w<=1000,1<=k<=w·h)$ .
The next $2h-1$ lines describe the color constraints from top to bottom, left to right. They contain $w-1,w,w-1,w,...,w-1$ characters respectively. Each color constraint is represented by a character "E" or "N", where "E" means " $=$ " and "N" means " $≠$ ".
The color constraints listed in the order they are depicted on the picture.
The next $2h-1$ lines describe the color constraints from top to bottom, left to right. They contain $w-1,w,w-1,w,...,w-1$ characters respectively. Each color constraint is represented by a character "E" or "N", where "E" means " $=$ " and "N" means " $≠$ ".
The color constraints listed in the order they are depicted on the picture.
输出格式
If there is a coloring that satisfies at least  of the color constraints, print "YES" (without quotes) in the first line. In each of the next $h$ lines, print $w$ integers describing the coloring.
Otherwise, print "NO" (without quotes).
Otherwise, print "NO" (without quotes).
输入输出样例
输入 #1
3 4 4 ENE NNEE NEE ENEN ENN
输出 #1
YES 1 1 2 2 3 4 1 1 3 3 2 4
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted