Educational Codeforces Round 106 (Rated for Div. 2) D. The Number of Pairs
3017. Count the Number of Houses at a Certain Distance II
You are given three positive integers
n,x, andy.In a city, there exist houses numbered
1tonconnected bynstreets. There is a street connecting the house numberediwith the house numberedi + 1for all1 <= i <= n - 1. An additional street connects the house numberedxwith the house numberedy.For each
k, such that1 <= k <= n, you need to find the number of pairs of houses(house1, house2)such that the minimum number of streets that need to be traveled to reachhouse2fromhouse1isk.Return a 1-indexed array
resultof lengthnwhereresult[k]represents the total number of pairs of houses such that the minimum streets required to reach one house from the other isk.Note that
xandycan be equal.
3016. Minimum Number of Pushes to Type Word II
You are given a string
wordcontaining lowercase English letters.Telephone keypads have keys mapped with distinct collections of lowercase English letters, which can be used to form words by pushing them. For example, the key
2is mapped with["a","b","c"], we need to push the key one time to type"a", two times to type"b", and three times to type"c".It is allowed to remap the keys numbered
2to9to distinct collections of letters. The keys can be remapped to any amount of letters, but each letter must be mapped to exactly one key. You need to find the minimum number of times the keys will be pushed to type the stringword.Return the minimum number of pushes needed to type
wordafter remapping the keys.An example mapping of letters to keys on a telephone keypad is given below. Note that
1,*,#, and0do not map to any letters.
3015. Count the Number of Houses at a Certain Distance I
You are given three positive integers
n,x, andy.In a city, there exist houses numbered
1tonconnected bynstreets. There is a street connecting the house numberediwith the house numberedi + 1for all1 <= i <= n - 1. An additional street connects the house numberedxwith the house numberedy.For each
k, such that1 <= k <= n, you need to find the number of pairs of houses(house1, house2)such that the minimum number of streets that need to be traveled to reachhouse2fromhouse1isk.Return a 1-indexed array
resultof lengthnwhereresult[k]represents the total number of pairs of houses such that the minimum streets required to reach one house from the other isk.Note that
xandycan be equal.
3014. Minimum Number of Pushes to Type Word I
You are given a string
wordcontaining distinct lowercase English letters.Telephone keypads have keys mapped with distinct collections of lowercase English letters, which can be used to form words by pushing them. For example, the key
2is mapped with["a","b","c"], we need to push the key one time to type"a", two times to type"b", and three times to type"c".It is allowed to remap the keys numbered
2to9to distinct collections of letters. The keys can be remapped to any amount of letters, but each letter must be mapped to exactly one key. You need to find the minimum number of times the keys will be pushed to type the stringword.Return the minimum number of pushes needed to type
wordafter remapping the keys.An example mapping of letters to keys on a telephone keypad is given below. Note that
1,*,#, and0do not map to any letters.