#K83242. Distinct Substrings Partition
Distinct Substrings Partition
Distinct Substrings Partition
You are given two strings S
and P
of length N, where P
is a permutation of S
, and an integer K. The task is to determine whether the string P
can be partitioned into exactly K non-empty contiguous substrings such that every substring consists of distinct characters.
This problem can be mathematically described by the following condition:
Let \( U(P) \) be the number of distinct characters in P
. The string P
can be partitioned into exactly K substrings with all distinct characters if and only if
[ U(P) \geq K ]
If the condition holds, output "Yes"; otherwise, output "No".
inputFormat
Input is read from standard input. The first line contains an integer N which is the length of the strings S
and P
. The second line contains the string S
. The third line contains the string P
(a permutation of S
). The fourth line contains an integer K indicating the number of required contiguous substrings.
outputFormat
Output a single line to standard output: "Yes" if it is possible to split string P
into exactly K non-empty contiguous substrings each having all distinct characters; otherwise, output "No".## sample
6
abacbc
cbabca
3
Yes
</p>