CodeForces 288A

72 阅读1分钟

A. Polo the Penguin and Strings

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 ass = s1s2... s**n, then the following inequality holds, s**i ≠ s**i + 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... x**p is lexicographically less than string y = y1y2... y**q, if either p < q andx1 = y1, x2 = y2, ... , x**p = y**p, or there is such number r (r < p, r < q), thatx1 = y1, x2 = y2, ... , x**r = y**r and x**r + 1 < y**r + 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).

Sample test(s)

input

7 4

output

ababacd

input

4 7

output

-1

 

 

极为简单的水题:比赛的时候没出,还是因为审题+极端数据的问题。在n>1,并且是m==1时应该输出-1而我输出了N个a..

将思路和重要的条件全部列在纸上。

 

#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

int main()
{
    int n,m,i,j,k;
    while(~scanf("%d%d",&n,&m))
    {
        if(n<m)
        {
            printf("-1\n");
            continue;
        }
        else if(m==1)
        {
            if(n>1)
            {
                printf("-1\n");
                continue;
            }
            else
            {
                printf("a\n");
                continue;
            }
        }
        int tmp=m-2;
        k=n-tmp;
        if(k%2)
        {
            k/=2;
            while(k--)
            {
                printf("ab");
            }
            printf("a");
        }
        else
        {
            k/=2;
            while(k--)
            {
                printf("ab");
            }
        }
        for(i=99; i<tmp+99; i++)
        {
            printf("%c",i);
        }
        printf("\n");
    }
    return 0;
}