CF1511D.Min Cost String

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Let's define the cost of a string ss as the number of index pairs ii and jj (1≤i<j<∣s∣1 \le i \lt j \lt |s|) such that si=sjs_i = s_j and si+1=sj+1s_{i+1} = s_{j+1}.

You are given two positive integers nn and kk. Among all strings with length nn that contain only the first kk characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost — find any of them.

我们定义字符串 ss 的代价为满足以下条件的下标对 (i,j)(i, j) 的数量:1≤i<j<∣s∣1 \le i \lt j \lt |s|,且 si=sjs_i = s_j 以及 si+1=sj+1s_{i+1} = s_{j+1}。

给定两个正整数 nn 和 kk。在所有长度为 nn、且仅由拉丁字母表前 kk 个字符组成的字符串中,找出一个代价最小的字符串。若存在多个代价最小的字符串,则输出任意一个即可。

输入格式

The only line contains two integers nn and kk (1≤n≤2⋅105;1≤k≤261 \le n \le 2 \cdot 10^5; 1 \le k \le 26).

唯一一行包含两个整数 nn 和 kk(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5;1≤k≤261 \le k \le 26)。

输出格式

Print the string ss such that it consists of nn characters, each its character is one of the kk first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings — print any of them.

输出字符串 ss,要求其长度为 nn,且每个字符均来自前 kk 个拉丁字母,并在所有满足条件的字符串中具有最小可能的代价。若存在多个满足条件的字符串,则输出其中任意一个即可。

输入输出样例

  • 输入#1

    9 4

    输出#1

    aabacadbb
  • 输入#2

    5 1

    输出#2

    aaaaa
  • 输入#3

    10 26

    输出#3

    codeforces

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

首页