0% found this document useful (0 votes)
34 views

CSEC-ASTU Competitive Programming Contest 2021 Problem 93: String Cutting

The document describes a string cutting problem. Given a string and a series of cuts that split the string into substrings, the task is to compute the total cost of the cuts, where the cost of each cut is the number of characters in either substring but not both. An example is provided where applying 3 cuts to the string "ababccd" at positions 5, 3, and 6 results in a total cost of 7. The input specifies the number of cuts, cut positions, and string, and the output should give the total cost.

Uploaded by

Abraham Mekuria
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

CSEC-ASTU Competitive Programming Contest 2021 Problem 93: String Cutting

The document describes a string cutting problem. Given a string and a series of cuts that split the string into substrings, the task is to compute the total cost of the cuts, where the cost of each cut is the number of characters in either substring but not both. An example is provided where applying 3 cuts to the string "ababccd" at positions 5, 3, and 6 results in a total cost of 7. The input specifies the number of cuts, cut positions, and string, and the output should give the total cost.

Uploaded by

Abraham Mekuria
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Mikias

Yonas

CSEC-ASTU Competitive Programming Contest 2021

Problem 93: String Cutting


Time limit: 3s

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.

Source: Uva Andalus Division August 3, 2021


Mikias
Yonas

CSEC-ASTU Competitive Programming Contest 2021


Sample Input Sample Output
2 7
3 4
5 3 6
ababccd
2
4 2
ababcd

Source: Uva Andalus Division August 3, 2021

You might also like