#P10986. Counting Occurrences of 2023 in N-digit Numbers

    ID: 13034 Type: Default 1000ms 256MiB

Counting Occurrences of 2023 in N-digit Numbers

Counting Occurrences of 2023 in N-digit Numbers

Given two integers \(n\) and \(m\), count how many \(n\)-digit decimal numbers (possibly with leading zeros) contain exactly \(m\) occurrences of the pattern \(2023\). The pattern is defined as a consecutive substring. For example, the 11-digit number 00202312023 contains exactly 2 occurrences of \(2023\) (one starting at the 3rd digit and another starting at the 8th digit).

Since the answer can be very large, output the result modulo \(998244353\).

Note: An occurrence of \(2023\) is counted using standard substring matching (overlapping occurrences are possible in general, but note that for the fixed pattern \(2023\) there is no possibility of overlapping because no non‐trivial suffix of \(2023\) is equal to its prefix).

The problem can be solved using dynamic programming by maintaining the current state of matching with \(2023\) (i.e. how many characters matched so far) along with the count of occurrences found.

inputFormat

The input consists of a single line containing two integers \(n\) and \(m\) (separated by a space):

  • \(n\): the number of digits of the integer (leading zeros are allowed).
  • \(m\): the exact number of occurrences of the substring \(2023\) that must appear.

outputFormat

Output a single integer, which is the number of \(n\)-digit numbers that contain exactly \(m\) occurrences of \(2023\), taken modulo \(998244353\).

sample

4 1
1