codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

110B.md (2081B)


      1 Source: https://codeforces.com/problemset/problem/110/B
      2 
      3 B. Lucky String
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 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.
     22 
     23 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.
     24 
     25 For example, let's consider string "zbcdzefdzc". The lists of positions of equal letters are:
     26 
     27 * b: 2
     28 * c: 3, 10
     29 * d: 4, 8
     30 * e: 6
     31 * f: 7
     32 * z: 1, 5, 9
     33 * Lists of positions of letters a, g, h, ..., y are empty.
     34 
     35 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.
     36 
     37 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.
     38 
     39 Find the lexicographically minimal lucky string whose length equals *n*.
     40 
     41 Input
     42 
     43 The single line contains a positive integer *n* (1 ≤ *n* ≤ 105) — the length of the sought string.
     44 
     45 Output
     46 
     47 Print on the single line the lexicographically minimal lucky string whose length equals *n*.
     48 
     49 Examples
     50 
     51 Input
     52 
     53 ```
     54 5
     55 ```
     56 
     57 Output
     58 
     59 ```
     60 abcda
     61 ```
     62 
     63 Input
     64 
     65 ```
     66 3
     67 ```
     68 
     69 Output
     70 
     71 ```
     72 abc
     73 ```
     74 
     75 Note
     76 
     77 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*.