CSEC-ASTU Competitive Programming Contest 2021 Problem 93: String Cutting
CSEC-ASTU Competitive Programming Contest 2021 Problem 93: String Cutting
Yonas
Let’s consider a string s of length n (0 < n < 10000) containing only characters from a
to z. We define a cut ci (0 < i < n) is an action splitting the string s into 2 substrings s1
and s2 so that s1 consists of first i characters of s and s2 consists of remaining characters
from s. Each cut is associated with a cost which equals to the total number of
characters consisted in either s1 or s2 but not in both. For example, let s = ‘abcbacbd’,
the cut c5 will break s into s1 = ‘abcba’ and s2 = ‘cbd’ with the cost of 2.
The original string can be cut into k + 1 substrings after applying k cuts sequentially to
the string and its subsequent substrings. In order to simply describe these k cuts, we
specify the position of the cuts with regard to the original string.
Let’s consider an example where we sequentially apply 3 cuts at positions 5, 3 and 6 to
the string s = ‘ababccd’. After the first cut at position 5, we have two substrings s1 =
‘ababc’ and s2 = ‘cd’ with the cost of 3. The second cut at position 3 breaks s1 into two
substrings s11 = ‘aba’ and s12 = ‘bc’ with the cost of 2. The last cut at position 6 breaks
s2 into two substrings s21 = ‘c’ and s22 = ‘d’ with the cost of 2. The total cost for the 3
cuts is 3+2+2=7. Given a string and their cuts, your task is to write a program to
compute the total cost for the cut.
Input
Each case of input starts with a positive integer N < 100. N lines follow each containing
at least 1 and at most 100 characters. The Input characters will consist of
alphanumeric, spaces, backslash and quotation only. The last case is followed by a value
of 0 for N.
For each data set, the first line contains the integer number k (1 ≤ k ≤ 1000). The
second line contains k positive integer numbers describing the position of k cuts. The
third line contains the string which will be cut.
Output
For each test case, write in one line the total cost of the cuts.