A8193 | Lucky String
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya recently learned to determine whether a string of lowercase Latin letters is lucky. For each individual letter all its positions in the string are written out in the increasing order. This results in $26$ lists of numbers; some of them can be empty. A string is considered lucky if and only if in each list the absolute difference of any two adjacent numbers is a lucky number.
For example, let's consider string "zbcdzefdzc". The lists of positions of equal letters are:
- b: $2$
- c: $3,10$
- d: $4,8$
- e: $6$
- f: $7$
- z: $1,5,9$
- Lists of positions of letters a, g, h, ..., y are empty.
This string is lucky as all differences are lucky numbers. For letters z: $5-1=4$ , $9-5=4$ , for letters c: $10-3=7$ , for letters d: $8-4=4$ .
Note that if some letter occurs only once in a string, it doesn't influence the string's luckiness after building the lists of positions of equal letters. The string where all the letters are distinct is considered lucky.
Find the lexicographically minimal lucky string whose length equals $n$ .
Petya recently learned to determine whether a string of lowercase Latin letters is lucky. For each individual letter all its positions in the string are written out in the increasing order. This results in $26$ lists of numbers; some of them can be empty. A string is considered lucky if and only if in each list the absolute difference of any two adjacent numbers is a lucky number.
For example, let's consider string "zbcdzefdzc". The lists of positions of equal letters are:
- b: $2$
- c: $3,10$
- d: $4,8$
- e: $6$
- f: $7$
- z: $1,5,9$
- Lists of positions of letters a, g, h, ..., y are empty.
This string is lucky as all differences are lucky numbers. For letters z: $5-1=4$ , $9-5=4$ , for letters c: $10-3=7$ , for letters d: $8-4=4$ .
Note that if some letter occurs only once in a string, it doesn't influence the string's luckiness after building the lists of positions of equal letters. The string where all the letters are distinct is considered lucky.
Find the lexicographically minimal lucky string whose length equals $n$ .
输入格式
The single line contains a positive integer $n$ ( $1<=n<=10^{5}$ ) — the length of the sought string.
输出格式
Print on the single line the lexicographically minimal lucky string whose length equals $n$ .
输入输出样例
输入 #1
5
输出 #1
abcda
输入 #2
3
输出 #2
abc
The lexical comparison of strings is performed by the < operator in modern programming languages. String $a$ is lexicographically less than string $b$ if exists such $i$ ( $1<=i<=n$ ), that $a_{i}<b_{i}$ , and for any $j$ ( $1<=j<i$ ) $a_{j}=b_{j}$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted