#C4046. Restore Hat Patterns

    ID: 47541 Type: Default 1000ms 256MiB

Restore Hat Patterns

Restore Hat Patterns

Given a shuffled string formed by concatenating several hat pattern strings, your task is to restore the original order of the hat patterns used to create the shuffled string. Each hat pattern is a string of fixed length m and there are n segments in the shuffled string (where n = length(shuffled_string)/m). You are also provided with h available hat patterns. Your goal is to determine if it is possible to partition the shuffled string into segments, such that each segment exactly matches one of the provided hat patterns.

If a valid reconstruction is possible, output "YES" on the first line followed by a second line containing n integers representing the 1-indexed positions of the patterns (from the provided list) in the order they appear in the shuffled string. Otherwise, output "NO".

Mathematically, the shuffled string is defined as: $$S = P_1P_2\ldots P_n$$ where each pattern \(P_i\) has length m and there exists an index mapping from the available hat patterns such that each \(P_i\) equals one of these patterns. Determine whether such a mapping exists, and if so, output the corresponding indices.

inputFormat

The first line contains three integers n, m, and h separated by spaces, where:

  • n is the number of segments in the shuffled string (note: n = length(shuffled_string)/m).
  • m is the length of each hat pattern.
  • h is the number of available hat patterns.

The second line contains the shuffled string.

Each of the next h lines contains one hat pattern.

outputFormat

If a valid reconstruction is possible, output "YES" on the first line, and on the second line output n integers representing the indices (1-indexed) of the hat patterns that form the shuffled string.

If no valid reconstruction exists, output "NO".

## sample
3 2 4
aabbcc
aa
bb
cc
dd
YES

1 2 3

</p>