#C13551. Shortest Distance to Character

    ID: 43102 Type: Default 1000ms 256MiB

Shortest Distance to Character

Shortest Distance to Character

Given a string \( s \) and a character \( c \), compute for each index \( i \) the minimum distance to any occurrence of \( c \) in \( s \). The distance for an index \( i \) is defined as \( |i - j| \) where \( s[j] = c \) and \( j \) is any valid index in \( s \). If \( c \) does not appear in \( s \), output \(-1\) for every position.

Detailed Explanation:

  • If character \( c \) is found in \( s \), then for every index \( i \) (0-indexed), you must determine \( \min_{j: s[j]=c} |i - j| \).
  • If \( c \) does not appear, every value in the result should be \(-1\).

Note: The answer list should be printed as space-separated integers on one line.

inputFormat

The input is provided via stdin and consists of two lines:

  1. The first line contains the string \( s \).
  2. The second line contains the character \( c \).

outputFormat

Output a single line containing the list of distances for each index in \( s \). The distances should be printed as space-separated integers. If \( c \) does not occur in \( s \), output \(-1\) for every index.

## sample
a
a
0