#P8417. Password Complexity Validation and Counting

    ID: 21593 Type: Default 1000ms 256MiB

Password Complexity Validation and Counting

Password Complexity Validation and Counting

In this problem, passwords are generated from digits and English letters (both uppercase and lowercase). A valid password must satisfy all of the following conditions:

  • The password length is at most R but at least L characters, and it must contain at least one digit and at least one letter.
  • The password cannot contain A consecutive identical characters. For example, if A = 3, then the substring "2333" (three consecutive '3's) is forbidden.
  • The password cannot contain B consecutive characters that form either an ascending or descending sequence. Here an ascending sequence is defined as any continuous substring of one of the strings below, and a descending sequence is the reverse of such a substring:
    0123456789, ABCDEFGHIJKLMNOPQRSTUVWXYZ, abcdefghijklmnopqrstuvwxyz
    For example, if B = 4, then "6789" is an ascending sequence and "FED" (if B = 3) is a descending sequence. Note that sequences like "90", "AZ", or "az" are not considered ascending or descending because they are not continuous subsequences of the given strings. Also, case‐sensitivity matters (e.g. "Def" is not a valid ascending sequence, though its substring "ef" might be checked if B = 2).

Assume the password characters come only from the set of 62 characters (digits and English letters). Given the integers L, A, B and R, count the number of valid passwords whose length is between L and R (inclusive).

Note: It is guaranteed that the parameters will be small enough so that a brute-force or recursive solution is feasible.

inputFormat

The input consists of four space-separated integers:

  1. L: minimum password length.
  2. A: the number of consecutive identical characters that is forbidden.
  3. B: the number of consecutive characters that if they form an ascending or descending sequence (from the given character sets) are forbidden.
  4. R: maximum password length.

For example:
1 2 2 2

outputFormat

Output a single integer denoting the number of valid passwords satisfying the conditions.

sample

1 2 2 1
0