[Solution] Hard Cut solution codeforces

Hard Cut solution codeforces – You are given a binary string 𝑠s. You have to cut it into any number of non-intersecting substrings, so that the sum of binary integers denoted by these substrings is a power of 2. Each element of 𝑠s should be in exactly one substring. [Solution] Hard Cut solution codeforces Each test contains … Read more

[Solution] Diverse Segments solution codeforces

Diverse Segments solution codeforces – You are given an array 𝑎a of 𝑛n integers. Also you are given 𝑚m subsegments of that array. The left and the right endpoints of the 𝑗j-th segment are 𝑙𝑗lj and 𝑟𝑗rj respectively. [Solution] Diverse Segments solution codeforces You are allowed to make no more than one operation. In that operation you choose any subsegment of the array 𝑎a and replace each value on … Read more

[Solution] MEX vs DIFF solution codeforces

MEX vs DIFF solution codeforces – You are given an array 𝑎a of 𝑛n non-negative integers. In one operation you can change any number in the array to any other non-negative integer. [Solution] MEX vs DIFF solution codeforces Let’s define the cost of the array as DIFF(𝑎)−MEX(𝑎)DIFF⁡(a)−MEX⁡(a), where MEXMEX of a set of non-negative integers is the smallest non-negative integer not present in … Read more

[Solution] Traps solution codeforces

Traps solution codeforces – There are 𝑛n traps numbered from 11 to 𝑛n. You will go through them one by one in order. The 𝑖i-th trap deals 𝑎𝑖ai base damage to you. [Solution] Traps solution codeforces Instead of going through a trap, you can jump it over. You can jump over no more than 𝑘k traps. If you jump over a trap, it does … Read more

[Solution] Column Swapping solution codeforces

Column Swapping solution codeforces – You are given a grid with 𝑛n rows and 𝑚m columns, where each cell has a positive integer written on it. Let’s call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each 1≤𝑖≤𝑛1≤i≤n and 2≤𝑗≤𝑚2≤j≤m the following holds: 𝑎𝑖,𝑗≥𝑎𝑖,𝑗−1ai,j≥ai,j−1. [Solution] Column Swapping solution codeforces You have … Read more

[Solution] Z mod X = C solution codeforces

Z mod X = C solution codeforces – You are given three positive integers 𝑎a, 𝑏b, 𝑐c (𝑎<𝑏<𝑐a<b<c). [Solution] Z mod X = C solution codeforces You have to find three positive integers 𝑥x, 𝑦y, 𝑧z such that: 𝑥mod𝑦=𝑎,xmody=a, 𝑦mod𝑧=𝑏,ymodz=b, 𝑧mod𝑥=𝑐.zmodx=c. Here 𝑝mod𝑞pmodq denotes the remainder from dividing 𝑝p by 𝑞q. It is possible to show that for such constraints the answer always exists. Input The input … Read more

[Solution] Digit Minimization solution codeforces

Digit Minimization solution codeforces – There is an integer 𝑛n without zeros in its decimal representation. Alice and Bob are playing a game with this integer. Alice starts first. They play the game in turns. [Solution] Digit Minimization solution codeforces On her turn, Alice must swap any two digits of the integer that are on different positions. Bob on … Read more

[Solution] Binary String Game solution codechef

Binary String Game solution codechef – There is a binary string SS. Alice and Bob are playing a game on it. Each turn, the following happens: Alice selects a 0101 subsequence in SS and removes it from SS. (a 0101 subsequence is a length 22 subsequence whose first character is 00 and second character is 11) Bob selects a 0101 subsequence in SS and removes it from SS. After both players have … Read more

[Solution] Smallest Element In Progression solution codechef

 Smallest Element In Progression solution codechef – You are given a prime number PP and two integers A,BA,B. Your task is to find the minimum value of (AT⋅B)modP(AT⋅B)modP over all nonnegative integers TT. [Solution] Smallest Element In Progression solution codechef The only line of input contains three space-separated integers P,A,BP,A,B. It’s guaranteed that PP is prime. Output Format Output the minimum value of (AT⋅B)modP(AT⋅B)modP over … Read more