Codeforces Round #302 (Div. 2) (ABCD题解)

比赛链接:

A. Set of Strings

time limit per test:1 second

memory limit per test:256 megabytes

You are given a string q. A sequence ofk strings s1,s2,…,sk is calledbeautiful, if the concatenation of these strings is stringq (formally, s1+s2+…+sk=q) and the first characters of these strings are distinct.

Find any beautiful sequence of strings or determine that thebeautiful sequence doesn’t exist.

Input

The first line contains a positive integer k (1≤k≤26) — the number of strings that should be in abeautiful sequence.

The second line contains string q, consisting of lowercase Latin letters. The length of the string is within range from1 to 100, inclusive.

Output

If such sequence doesn’t exist, then print in a single line "NO" (without the quotes). Otherwise, print in the first line "YES" (without the quotes) and in the nextk lines print the beautiful sequence of strings s1,s2,…,sk.

If there are multiple possible answers, print any of them.

Sample test(s)

Input

1abca

Output

YESabca

Input

2aaacas

Output

YESaaacas

Input

4abc

Output

NO

Note

In the second sample there are two possible answers:{"aaaca","s"} and {"aaa","cas"}.

题目大意:把一个给定的母串分成k个子串,要求k个子串的和为母串,,且k个子串的首字符不能相同

题目分析:标记一下首字符出现的情况再统计一下分成的份数即可

#include <cstdio>#include <iostream>#include <string>#include <cstring>using namespace std;int main(){int k;cin >> k;string s;cin >> s;string ans[30];int cnt = 1;int len = s.length();bool hash[400];memset(hash, false, sizeof(hash));bool flag = false;for(int i = 0; i < len; i++){if(!hash[s[i]]){hash[s[i]] = true;ans[cnt ++] += s[i];}else if(hash[s[i]] || s[i] == s[i – 1])ans[cnt – 1] += s[i];if(cnt == k + 1){for(int j = i + 1; j < len; j++)ans[cnt – 1] += s[j];flag = true;break;}}if(!flag)printf("NO\n");else{printf("YES\n");for(int i = 1; i < cnt; i++)cout << ans[i] << endl;}}

B. Sea and Islands

time limit per test:1 second

memory limit per test:256 megabytes

A map of some object is a rectangular field consisting ofn 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 exactlyk islands appear on the map. We will call a set of sand cells to beisland 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 exactlyk islands appear on the n×n map, or determine that no such way exists.

Input

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

Output

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

Otherwise, print "YES" in the first line. In the nextn 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 equaln.

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

You should not maximize the sizes of islands.

Sample test(s)

Input

5 2

Output

YESSSSSSLLLLLSSSSSLLLLLSSSSS

Input

5 25

Output

NO

题目大意:把一个区域分成k个岛输出方案,岛就是一个四个方向的连通块

题目分析:隔一格,填一个岛,填到k个为止,注意最多可能出现的岛的个数为(n * n + 1) / 2

效果只能是既费时又没有胜利,再聪慧的人也没法成学。

Codeforces Round #302 (Div. 2) (ABCD题解)

相关文章:

你感兴趣的文章:

标签云: