Codeforces Round 892 (Div. 2) D. Andrey and Escape from Capygrad
10038. Minimum Cost to Convert String II
ou are given two 0-indexed strings
sourceandtarget, both of lengthnand consisting of lowercase English characters. You are also given two 0-indexed string arraysoriginalandchanged, and an integer arraycost, wherecost[i]represents the cost of converting the stringoriginal[i]to the stringchanged[i].You start with the string
source. In one operation, you can pick a substringxfrom the string, and change it toyat a cost ofzif there exists any indexjsuch thatcost[j] == z,original[j] == x, andchanged[j] == y. You are allowed to do any number of operations, but any pair of operations must satisfy either of these two conditions:
- The substrings picked in the operations are
source[a..b]andsource[c..d]with eitherb < cord < a. In other words, the indices picked in both operations are disjoint.- The substrings picked in the operations are
source[a..b]andsource[c..d]witha == candb == d. In other words, the indices picked in both operations are identical.Return the minimum cost to convert the string
sourceto the stringtargetusing any number of operations. If it is impossible to convertsourcetotarget, return-1.Note that there may exist indices
i,jsuch thatoriginal[j] == original[i]andchanged[j] == changed[i].
10037. Minimum Cost to Convert String I
You are given two 0-indexed strings
sourceandtarget, both of lengthnand consisting of lowercase English letters. You are also given two 0-indexed character arraysoriginalandchanged, and an integer arraycost, wherecost[i]represents the cost of changing the characteroriginal[i]to the characterchanged[i].You start with the string
source. In one operation, you can pick a characterxfrom the string and change it to the characteryat a cost ofzif there exists any indexjsuch thatcost[j] == z,original[j] == x, andchanged[j] == y.Return the minimum cost to convert the string
sourceto the stringtargetusing any number of operations. If it is impossible to convertsourcetotarget, return-1.Note that there may exist indices
i,jsuch thatoriginal[j] == original[i]andchanged[j] == changed[i].
10036. Maximum Square Area by Removing Fences From a Field
There is a large
(m - 1) x (n - 1)rectangular field with corners at(1, 1)and(m, n)containing some horizontal and vertical fences given in arrayshFencesandvFencesrespectively.Horizontal fences are from the coordinates
(hFences[i], 1)to(hFences[i], n)and vertical fences are from the coordinates(1, vFences[i])to(m, vFences[i]).Return the maximum area of a square field that can be formed by removing some fences (possibly none) or
-1if it is impossible to make a square field.Since the answer may be large, return it modulo
109 + 7.Note: The field is surrounded by two horizontal fences from the coordinates
(1, 1)to(1, n)and(m, 1)to(m, n)and two vertical fences from the coordinates(1, 1)to(m, 1)and(1, n)to(m, n). These fences cannot be removed.
You are given a 0-indexed integer array
numsof even length and there is also an empty arrayarr. Alice and Bob decided to play a game where in every round Alice and Bob will do one move. The rules of the game are as follows:
- Every round, first Alice will remove the minimum element from
nums, and then Bob does the same.- Now, first Bob will append the removed element in the array
arr, and then Alice does the same.- The game continues until
numsbecomes empty.Return the resulting array
arr.