Substring 2

AtCoder
IDabc438_b
Time2000ms
Memory256MB
Difficulty
You are given integers $N$ and $M$, a digit string $S$ of length $N$, and a digit string $T$ of length $M$. Here, a digit string is a string consisting of digits from `0` to `9`. You can perform the following operation zero or more times: * Choose one character from $T$ and increase the chosen digit by $1$. However, if the chosen digit is `9`, change it to `0`. Find the minimum number of operations required to make $T$ a substring (**contiguous** subsequence) of $S$. ## Constraints * $1\le M\le N\le 100$ * $N$ and $M$ are integers. * $S$ is a digit string of length $N$. * $T$ is a digit string of length $M$. ## Input The input is given from Standard Input in the following format: $N$ $M$ $S$ $T$ [samples]
Samples
Input #1
4 2
2025
91
Output #1
2

You can make $T$ a substring of $S$ with two operations as follows:

*   Perform the operation on the $2$nd character of $T$. $T=$ `91` becomes $T=$ `92`.
*   Perform the operation on the $1$st character of $T$. $T=$ `92` becomes $T=$ `02`.

`02` is a substring from the $2$nd character to the $3$rd character of $S$.
It is impossible to make $T$ a substring of $S$ with less than two operations, so output $2$.
Input #2
3 2
438
38
Output #2
0

`38` is a substring of `438` from the beginning. Thus, output $0$.
Input #3
5 5
00000
11111
Output #3
45
Input #4
8 3
20251227
438
Output #4
13
API Response (JSON)
{
  "problem": {
    "name": "Substring 2",
    "description": {
      "content": "You are given integers $N$ and $M$, a digit string $S$ of length $N$, and a digit string $T$ of length $M$. Here, a digit string is a string consisting of digits from `0` to `9`. You can perform the f",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc438_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given integers $N$ and $M$, a digit string $S$ of length $N$, and a digit string $T$ of length $M$. Here, a digit string is a string consisting of digits from `0` to `9`.\nYou can perform the f...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments