Educational Codeforces Round 75 (Rated for Div. 2) D. Salary Changing
2791. Count Paths That Can Form a Palindrome in a Tree
You are given a tree (i.e. a connected, undirected graph that has no cycles) rooted at node
0consisting ofnnodes numbered from0ton - 1. The tree is represented by a 0-indexed arrayparentof sizen, whereparent[i]is the parent of nodei. Since node0is the root,parent[0] == -1.You are also given a string
sof lengthn, wheres[i]is the character assigned to the edge betweeniandparent[i].s[0]can be ignored.Return the number of pairs of nodes
(u, v)such thatu < vand the characters assigned to edges on the path fromutovcan be rearranged to form a palindrome.A string is a palindrome when it reads the same backwards as forwards.
2790. Maximum Number of Groups With Increasing Length
You are given a 0-indexed array
usageLimitsof lengthn.Your task is to create groups using numbers from
0ton - 1, ensuring that each number,i, is used no more thanusageLimits[i]times in total across all groups. You must also satisfy the following conditions:
- Each group must consist of distinct numbers, meaning that no duplicate numbers are allowed within a single group.
- Each group (except the first one) must have a length strictly greater than the previous group.
Return an integer denoting the maximum number of groups you can create while satisfying these conditions.
2789. Largest Element in an Array after Merge Operations
You are given a 0-indexed array
numsconsisting of positive integers.You can do the following operation on the array any number of times:
- Choose an integer
isuch that0 <= i < nums.length - 1andnums[i] <= nums[i + 1]. Replace the elementnums[i + 1]withnums[i] + nums[i + 1]and delete the elementnums[i]from the array.Return the value of the largest element that you can possibly obtain in the final array.
2788. Split Strings by Separator
Given an array of strings
wordsand a characterseparator, split each string inwordsbyseparator.Return an array of strings containing the new strings formed after the splits, excluding empty strings.
Notes
separatoris used to determine where the split should occur, but it is not included as part of the resulting strings.- A split may result in more than two strings.
- The resulting strings must maintain the same order as they were initially given.
2787. Ways to Express an Integer as Sum of Powers
Given two positive integers
nandx.Return the number of ways
ncan be expressed as the sum of thexthpower of unique positive integers, in other words, the number of sets of unique integers[n1, n2, ..., nk]wheren = n1x + n2x + ... + nkx.Since the result can be very large, return it modulo
109 + 7.For example, if
n = 160andx = 3, one way to expressnisn = 23 + 33 + 53.