INCDIGIT - Editorial

PROBLEM LINK:

Practice
Contest

Author: Hrishikesh Patel
Tester: Roshan Gupta, Shivam Sarang, Yash Shah
Editorialist: Yash Shah

DIFFICULTY:

EASY-MEDIUM

PROBLEM:

Given an integer n, Increment its digits k times.



When a 9 is incremented, it becomes 2 different digits (1, 0).
For example, if 191 is the number, after incrementing once, it becomes 2102. Then after incrementing once more, it becomes 3213.



We want to count the number of digits in the number after incrementing k times.
Note :- As the answer could be large return the answer modulo 10 ^ 9.

Input Format:

  • First line contains a single integer, t, which gives the number of test cases.
  • Each testcase contains 2 integers separated by space:
  • First integer gives the number, n.
  • Second integer gives the number of times increment operation is to be performed, k.

Output Format:

  • t lines containing single integer, the output for each testcase.

EXPLANATION:

Sample Test Case:

Input:
3
191 2
101 12
16 21

Output:
4
6
8

  • For first testcase same as in the description.
  • For second testcase after incrementing 8 times, number is 989. By incrementing 9th time, the number becomes 10910, then incrementing again gives 211021. Finally, after incrementing 12th time, the number is 433243.

SOLUTIONS:

Setter's Solution
n = 0
m = 2 * 10**5
a = [0 for _ in range(10)]
b = [0 for _ in range(10)]
ans = [0 for _ in range(m + 20)]

a[0] = 1
for j in range(m + 10):
    b[0] = a[9]
    b[1] = a[9] + a[0] % 1000000007
    b[2] = a[1]
    b[3] = a[2]
    b[4] = a[3]
    b[5] = a[4]
    b[6] = a[5]
    b[7] = a[6]
    b[8] = a[7]
    b[9] = a[8]

    a = [x for x in b]
    ans[j] = sum(a) % 1000000007

T = int(input())
for _ in range(T):
    n, m = input().split()
    m = int(m)
    s = 0

    for i in n:
	    s += ans[m + int(i) - 1]
    print(s % 1000000007)