F - Set of Strings
You are given a string q. A sequence of k strings s1, s2, ..., sk is called beautiful, if the concatenation of these strings is string q (formally, s1 + s2 + ... + sk = q) and the first characters of these strings are distinct.
Find any beautiful sequence of strings or determine that the beautiful sequence doesn't exist.
Input
The first line contains a positive integer k (1 ≤ k ≤ 26) — the number of strings that should be in a beautiful sequence.
The second line contains string q, consisting of lowercase Latin letters. The length of the string is within range from 1 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 next k lines print the beautiful sequence of strings s1, s2, ..., sk.
If there are multiple possible answers, print any of them.
Examples
Input
1
abca
Output
YES
abca
Input
2
aaacas
Output
YES
aaa
cas
Input
4
abc
Output
NO
Note
In the second sample there are two possible answers: {"aaaca", "s"} and {"aaa", "cas"}.
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<queue>
using namespace std;
map<char,int >wakaka;
int a[1010];
int main()
{
int n;
cin>>n;
memset(a,0,sizeof(a));
string s;
cin>>s;
int len=s.size();
if(len<n)
{
cout<<"NO"<<endl;
}
else
{
a[0]=0;
int ans=0;
for(int i=0; i<len; i++)
{
if(wakaka[s[i]]==0)
{
ans++;
a[ans]=i;
}
wakaka[s[i]]++;
}
if(ans>=n)
{
cout<<"YES"<<endl;
for(int i=1; i<=ans; i++)
{
if(i==n)
{
for(int j=a[i]; j<len; j++)
{
cout<<s[j];
}
break;
}
for(int j=a[i]; j<a[i+1]; j++)
{
cout<<s[j];
}
cout<<endl;
}
}
else
{
cout<<"NO"<<endl;
}
}
return 0;
}
F - Set of Strings的更多相关文章
- Codeforces Round #598 (Div. 3) F. Equalizing Two Strings 构造
F. Equalizing Two Strings You are given two strings s and t both of length n and both consisting of ...
- Codeforces Round #598 (Div. 3) F. Equalizing Two Strings
You are given two strings ss and tt both of length nn and both consisting of lowercase Latin letters ...
- golang --strings 下常用函数api
1. func Compare(a, b string) int {} 比较返回一个按字典顺序比较两个字符串的整数.如果a == b则结果为0,如果a <b则结果为-1,如果a> b则结果 ...
- Equalizing Two Strings
F. Equalizing Two Strings 有几种情况可以直接判定结果: ① 字母对应个数不一样,可直接判NO ② 当不满足①时,如果有一个字母有2个及以上的个数,也可直接判YES ③ 当不满 ...
- float_array.go
) if err != nil { log.Fatalf("Could not parse: %s", s) ret ...
- JavaSE_List&Array_Java1.7
这里简单写了下List和Array的相互转换 package cn.rocker.collection.list; import org.junit.Test; import java.util.Ar ...
- 驳2B文 "我为什么放弃Go语言"
此篇文章流传甚广, 其实里面没啥干货, 而且里面很多观点是有问题的. 这个文章在 golang-china 很早就讨论过了. 最近因为 Rust 1.0 和 1.1 的发布, 导致这个文章又出来毒 ...
- [日常] Go语言圣经-错误,函数值习题
Go语言圣经-错误 1.panic异常.panic是来自被调函数的信号,表示发生了某个已知的bug 2.任何进行I/O操作的函数都会面临出现错误的可能 3.错误是软件包API和应用程序用户界面的一个重 ...
- AtCoder Regular Contest
一句话题解 因为上篇AGC的写的有点长……估计这篇也短不了所以放个一句话题解方便查阅啥的吧QwQ 具体的题意代码题解还是往下翻…… ARC 058 D:简单容斥计数. E:用二进制表示放的数字,然后状 ...
随机推荐
- BZOJ1419Red is good——概率DP
题目描述 桌面上有R张红牌和B张黑牌,随机打乱顺序后放在桌面上,开始一张一张地翻牌,翻到红牌得到1美元,黑牌则付 出1美元.可以随时停止翻牌,在最优策略下平均能得到多少钱. 输入 一行输入两个数R,B ...
- BZOJ2212 POI2011Tree Rotations(线段树合并)
显然子树内的操作不会对子树外产生影响.于是贪心,若交换之后子树内逆序对减少就交换. 这个东西可以用权值线段树计算.操作完毕后需要对两棵权值线段树合并,这个的复杂度是两棵线段树的重复节点个数.那么总复杂 ...
- 博弈论基础知识: 巴什博奕+斐波那契博弈+威佐夫博奕+尼姆博弈(及Staircase)(转)
(一)巴什博奕(Bash Game):只有一堆n个物品,两个人轮流从这堆物品中取物,规定每次至少取一个,最多取m个.最后取光者得胜.若(m+1) | n,则先手必败,否则先手必胜.显然,如果n=m+1 ...
- day10 递归
死循环,因此递归必须要定义一个明确的结束条件 def calc(n): print(n) calc(n) calc(10) return 表示终止符号,最终会得出一个确切的返回值,且可以赋值 def ...
- 搬进Github
学习参考 萌码 一.Github简介和基本操作 Github 上操作基本上围绕一个个项目展开.项目就是一个文件夹,在github中成为“仓库”(repository),里面放着所有的项目文件,可以是代 ...
- 【CodeForces 624D/623B】Array GCD
题 You are given array ai of length n. You may consecutively apply two operations to this array: remo ...
- 17 利用Zabbix完成VMare监控
点击返回:自学Zabbix之路 17 利用Zabbix完成VMare监控 最近在研究通过Zabbix监控VMware vSphere,Zabbix Documentation 3.0 从文档中我们看到 ...
- 洛谷 P2812 校园网络【[USACO]Network of Schools加强版】 解题报告
P2812 校园网络[[USACO]Network of Schools加强版] 题目背景 浙江省的几所OI强校的神犇发明了一种人工智能,可以AC任何题目,所以他们决定建立一个网络来共享这个软件.但是 ...
- 【洛谷P3792】由乃与大母神原型和偶像崇拜
题目大意:维护一个序列,支持单点修改和查询一段区间能不能组成连续的一段数. 题解:查询区间能不能组成一段连续的数这个操作较为复杂,很难在较小时间复杂度内直接维护.这里采用线段树维护区间哈希的策略,即: ...
- asp(utf-8) set cookie 用 javascript 读cookie发现一个问题
asp: <%setCookie("user_id","test")%> //传一个cookie ,名: user_id 值:test java ...