Description

Little penguin Polo adores strings. But most of all he adores strings of length n.

One day he wanted to find a string that meets the following conditions:

  1. The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct.
  2. No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds, si ≠ si + 1(1 ≤ i < n).
  3. Among all strings that meet points 1 and 2, the required string is lexicographically smallest.

Help him find such string or state that such string doesn't exist.

String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes.

Input

A single line contains two positive integers n and k (1 ≤ n ≤ 106, 1 ≤ k ≤ 26) — the string's length and the number of distinct letters.

Output

In a single line print the required string. If there isn't such string, print "-1" (without the quotes).

Examples
Input
7 4
Output
ababacd
Input
4 7
Output
-1

正解:贪心
解题报告:
  直接每次贪心地让ab不断重复,注意特判一些细节,这题的数据好坑
 //It is made by jump~
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
int n,k,cnt; inline int getint()
{
int w=,q=; char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar(); if(c=='-') q=,c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar(); return q ? -w : w;
} inline void work(){
n=getint(); k=getint();
if(k>n || (k== && n>)) { printf("-1"); return ; }
if(k== && n==) { printf("a"); return ; }
cnt=; k-=;
for(int i=;i<=n;i++) {
if(n-i<k) printf("%c",(char)cnt+'a'),cnt++;
else {
if(i&) printf("a"); else printf("b");
}
}
} int main()
{
work();
return ;
}

codeforces 288A:Polo the Penguin and Strings的更多相关文章

  1. CodeForces 288A Polo the Penguin and Strings (水题)

    题意:给定一个字符,让你用前 k 个字符把它排成 n 长度,相邻的字符不能相等,并且把字典序最小. 析:其实很简单么,我们只要多循环ab,就行,最后再把剩下的放上,要注意k为1的时候. 代码如下: # ...

  2. A. Polo the Penguin and Strings

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  3. CodeForces - 616F:Expensive Strings (后缀自动机)

    You are given n strings ti. Each string has cost ci. Let's define the function of string , where ps, ...

  4. codeforces B. Polo the Penguin and Matrix 解题报告

    题目链接:http://codeforces.com/problemset/problem/289/B 题目意思:给出一个 n 行 m 列的矩阵和数值 d .通过对矩阵里面的数进行 + d 或者 - ...

  5. Codeforces 288E - Polo the Penguin and Lucky Numbers(数位 dp+推式子)

    题目传送门 似乎我的解法和官方题解不太一样 纪念自己独立做出来的一道难度 2800 的题. 我们记 \(ans(x)\) 为 \([444...44,x]\) 的答案,显然答案为 \(ans(r)-a ...

  6. Codeforces 1105B:Zuhair and Strings(字符串水题)

    time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: sta ...

  7. CodeForces 288C Polo the Penguin and XOR operation (位运算,异或)

    题意:给一个数 n,让你求一个排列,使得这个排列与0-n的对应数的异或之最大. 析:既然是异或就得考虑异或的用法,然后想怎么才是最大呢,如果两个数二进制数正好互补,不就最大了么,比如,一个数是100, ...

  8. CodeForces 288B Polo the Penguin and Houses (暴力或都快速幂)

    题意:给定 n 和k,n 表示有n个房子,然后每个有一个编号,一只鹅要从一个房间中开始走,下一站就是房间的编号,现在要你求出有多少种方法编号并满足下面的要求: 1.如果从1-k房间开始走,一定能直到 ...

  9. CodeForces 289B Polo the Penguin and Matrix (数学,中位数)

    题意:给定 n * m 个数,然后每次只能把其中一个数减少d, 问你能不能最后所有的数相等. 析:很简单么,首先这个矩阵没什么用,用一维的存,然后找那个中位数即可,如果所有的数减去中位数,都能整除d, ...

随机推荐

  1. javascript从url中获取请求参数

    function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)( ...

  2. bean的作用域

    bean的作用域为singleton,spring容器中只存在一个bean的实例,所有对该bean的请求只返回同一个bean实例. 当bean的作用域为prototype时,每一次对bean的请求,都 ...

  3. js控制只能输入数字和小数点

    非常好用,代码示例如下: <input  onkeypress = "return event.keyCode>=48&&event.keyCode<=57 ...

  4. iOS:实现图片的无限轮播之使用第三方库SDCycleScrollView

    下载链接:github不断更新地址:https://github.com/gsdios/SDCycleScrollView #import "ViewController.h" # ...

  5. Jenkins进阶系列之——07更改Jenkins的主目录

    Jenkins默认会存放在用户主目录下的.jenkins文件夹中 如:Linux root用户:/root/.jenkins 注意:这是linux版本的.windows系统请自行更改.这个值在Jenk ...

  6. 开源搜索引擎Iveely 0.7.0发布,不一样,那就让他不一样!

    2012年08月05日,Iveely Search Engine 0.1.0发布,今天,怀着对于未来的追求,终于,0.7.0如期和大家见面了,7个版本,历时2年4个月,感谢大家的支持,感谢我不离不弃的 ...

  7. 微信小程序剖析【下】:运行机制

    在上一篇<微信小程序「官方示例代码」浅析[上]>中,我们只是简单的罗列了一下代码,这一篇,让我们来玩点刺激的——就是看看IDE的代码,了解它是怎么运行的. 还好微信的开发团队在软件工程的实 ...

  8. Git.Framework 框架随手记--ORM编辑删除

    前面一篇文章<Git.Framework 框架随手记--ORM新增操作>主要讲解了如何使用Git.Framework往数据库中添加数据.其操作过程相对简单,本章主要记录如何编辑数据和修改数 ...

  9. Python2和Python3 爬虫 转换

    由于Python3的不断完善,很多新入Python的小伙伴选择了Python3的阵营,很多人选择了爬虫这一热门话题,但是网络上大部分教程都是Python2 教程,Python3这一块做了些许的改动,对 ...

  10. node判断文件目录是否存在

    'use strict'; //这是一个简单的应用 var path = require('path'); var fs = require("fs") ; global.l = ...