BPC 1 J4 - Assignment of the Year

View as PDF

Submit solution


Points: 10 (partial)
Time limit: 1.5s
Memory limit: 512M

Authors:
Problem type

This year at Spirit of Math Schools, you have been assigned to find the number of unique numbers between 0 and M (inclusive) you can create using a list of N digits. You may add or concatenate digits. Their order must be maintained, and every digit must be used. Output the number of unique values you can create between 0 and M.

Constraints

1NM104

Subtask 1 [10%]

All of the digits are the same.

Subtask 2 [90%]

No additional constraints.

Input Specification

The first line contains two integers, N and M.

The next line contains a string of N digits (numbers between 0 and 9).

Output Specification

Output a single line containing an integer, the number of unique values that can be created.

Sample Input

Copy
4 100
1996

Sample Output

Copy
2

Explanation for Sample

There are 8 possible combinations of operations:

1+9+9+6=251+9+96=1061+99+6=1061+996=99719+9+6=3419+96=115199+6=2051996=1996

Only two of these are between 0 and 100 (25 and 34).


Comments