Helvetic Coding Contest 2024 online mirror (teams allowed, unrated) E1. Trails (Easy)
1945. Sum of Digits of String After Convert
You are given a string
sconsisting of lowercase English letters, and an integerk.First, convert
sinto an integer by replacing each letter with its position in the alphabet (i.e., replace'a'with1,'b'with2, …,'z'with26). Then, transform the integer by replacing it with the sum of its digits. Repeat the transform operationktimes in total.For example, if
s = "zbax"andk = 2, then the resulting integer would be8by the following operations:
- Convert:
"zbax" ➝ "(26)(2)(1)(24)" ➝ "262124" ➝ 262124- Transform #1:
262124 ➝ 2 + 6 + 2 + 1 + 2 + 4 ➝ 17- Transform #2:
17 ➝ 1 + 7 ➝ 8Return the resulting integer after performing the operations described above.
3277. Maximum XOR Score Subarray Queries
You are given an array
numsofnintegers, and a 2D integer arrayqueriesof sizeq, wherequeries[i] = [li, ri].For each query, you must find the maximum XOR score of any subarray of
nums[li..ri].The XOR score of an array
ais found by repeatedly applying the following operations onaso that only one element remains, that is the score:
- Simultaneously replace
a[i]witha[i] XOR a[i + 1]for all indicesiexcept the last one.- Remove the last element of
a.Return an array
answerof sizeqwhereanswer[i]is the answer to queryi.
3276. Select Cells in Grid With Maximum Score
You are given a 2D matrix
gridconsisting of positive integers.You have to select one or more cells from the matrix such that the following conditions are satisfied:
- No two selected cells are in the same row of the matrix.
- The values in the set of selected cells are unique.
Your score will be the sum of the values of the selected cells.
Return the maximum score you can achieve.
3275. K-th Nearest Obstacle Queries
There is an infinite 2D plane.
You are given a positive integer
k. You are also given a 2D arrayqueries, which contains the following queries:
queries[i] = [x, y]: Build an obstacle at coordinate(x, y)in the plane. It is guaranteed that there is no obstacle at this coordinate when this query is made.After each query, you need to find the distance of the
kthnearest obstacle from the origin.Return an integer array
resultswhereresults[i]denotes thekthnearest obstacle after queryi, orresults[i] == -1if there are less thankobstacles.Note that initially there are no obstacles anywhere.
The distance of an obstacle at coordinate
(x, y)from the origin is given by|x| + |y|.
3274. Check if Two Chessboard Squares Have the Same Color
You are given two strings,
coordinate1andcoordinate2, representing the coordinates of a square on an8 x 8chessboard.Below is the chessboard for reference.
Return
trueif these two squares have the same color andfalseotherwise.The coordinate will always represent a valid chessboard square. The coordinate will always have the letter first (indicating its column), and the number second (indicating its row).