#K67152. Wall Construction Challenge
Wall Construction Challenge
Wall Construction Challenge
You are given three integers r
, c
, and n
representing the number of rows, columns, and available colors respectively. Your task is to determine whether it is possible to construct a wall (an r by c grid) such that no two adjacent bricks (sharing an edge horizontally or vertically) have the same color.
The key observation is that when both r and c are greater than 1, at least two different colors are needed. In the case where either r = 1 or c = 1, a single color suffices since there is no possibility of having a brick with neighbors both above and below (or left and right). In mathematical terms, the minimum number of colors required is given by \[ \text{minColors} = \begin{cases} 2, & \text{if } \min(r, c) > 1 \\ 1, & \text{otherwise} \end{cases} \]
Output "YES" if the available colors n
are greater than or equal to minColors
, otherwise output "NO".
inputFormat
The input consists of a single line containing three space-separated integers: r
c
n
.
outputFormat
Output a single line containing either "YES" if it is possible to construct the wall under the given restrictions, or "NO" otherwise.
## sample2 2 4
YES
</p>