CF544B.Sea and Islands

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A map of some object is a rectangular field consisting of n rows and n columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly k islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to each of them by moving only through sand cells and by moving from a cell only to a side-adjacent cell. The cells are called to be side-adjacent if they share a vertical or horizontal side. It is easy to see that islands do not share cells (otherwise they together form a bigger island).

Find a way to cover some cells with sand so that exactly k islands appear on the n × n map, or determine that no such way exists.

某物体的地图是一个由 nn 行 nn 列组成的矩形区域。每个格子初始状态均为海洋,但你可以将地图中某些格子覆盖为沙地,使得地图上恰好出现 kk 个岛屿。我们称一组沙地格子为一个岛屿,当且仅当该组中任意两个沙地格子之间均存在一条路径,该路径仅经过沙地格子,且每次只能移动到与当前格子共享一条竖直或水平边(即上下左右相邻)的沙地格子。显然,不同岛屿之间不共享任何格子(否则它们将合并成一个更大的岛屿)。

请找出一种将某些格子覆盖为沙地的方法,使得在 n×nn \times n 的地图上恰好形成 kk 个岛屿;若不存在这样的方法,则判定其不可能。

输入格式

The single line contains two positive integers n, k (1 ≤ n ≤ 100, 0 ≤ k ≤ _n_2) — the size of the map and the number of islands you should form.

单行包含两个正整数 nn、kk(1 ≤ n ≤ 1001 \leq n \leq 100,0 ≤ k ≤ n20 \leq k \leq n^2)——分别为地图的大小以及你需要形成的岛屿数量。

输出格式

If the answer doesn't exist, print "NO" (without the quotes) in a single line.

Otherwise, print "YES" in the first line. In the next n lines print the description of the map. Each of the lines of the description must consist only of characters 'S' and 'L', where 'S' is a cell that is occupied by the sea and 'L' is the cell covered with sand. The length of each line of the description must equal n.

If there are multiple answers, you may print any of them.

You should not maximize the sizes of islands.

如果答案不存在,则在单独一行中输出 "NO"(不带引号)。

否则,在第一行输出 "YES"。接下来的 n 行中输出地图的描述。描述的每一行仅能由字符 'S' 和 'L' 组成,其中 'S' 表示被海水占据的格子,'L' 表示被沙子覆盖的格子。描述中每一行的长度必须等于 n。

若存在多个答案,可输出其中任意一个。

你不应最大化岛屿的大小。

输入输出样例

  • 输入#1

    5 2

    输出#1

    YES
    SSSSS
    LLLLL
    SSSSS
    LLLLL
    SSSSS
  • 输入#2

    5 25

    输出#2

    NO

输入解题思路,AI测评打分。不知道怎么写?

首页