[SOLUTION] Sorting with Twos Solution Codeforces

A. [SOLUTION] Sorting with Twos Solution Codeforces time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an array of integers a1,a2,…,an�1,�2,…,��. In one operation, you do the following: Choose a non-negative integer m�, such that 2m≤n2�≤�. Subtract 11 from ai�� for all integers i�, such that 1≤i≤2m1≤�≤2�. Can you sort the array … Read more

Doremy’s Connecting Plan Solution

Doremy’s Connecting Plan Solution Doremy lives in a country consisting of n cities numbered from 1 to n , with ai people living in the i -th city. It can be modeled as an undirected graph with n nodes. Doremy resides in a country composed of �n cities, numbered from 1 to �n, each housing … Read more

[Solution] Qingshan Loves Strings 2 Solution Codeforces

[Solution] Qingshan Loves Strings 2 Solution Codeforces time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Qingshan has a string s� which only contains 00 and 11. A string a� of length k� is good if and only if ai≠ak−i+1��≠��−�+1 for all i=1,2,…,k�=1,2,…,�. For Div. 2 contestants, note that this condition is different from the condition in … Read more

 [Solution] Subarrays Distinct Element Sum of Squares I Solution Leetcode

Subarrays Distinct Element Sum of Squares I Solution Leetcode User Accepted:0 User Tried:0 Total Accepted:0 Total Submissions:0 Difficulty:Easy You are given a 0-indexed integer array nums. The distinct count of a subarray of nums is defined as: Let nums[i..j] be a subarray of nums consisting of all the indices from i to j such that 0 <= i <= j < nums.length. Then the number of distinct values in nums[i..j] is called the … Read more

Subarrays Distinct Element Sum of Squares II Solution Leetcode

Subarrays Distinct Element Sum of Squares II Solution Leetcode User Accepted:0 User Tried:0 Total Accepted:0 Total Submissions:0 Difficulty:Hard You are given a 0-indexed integer array nums. The distinct count of a subarray of nums is defined as: Let nums[i..j] be a subarray of nums consisting of all the indices from i to j such that 0 <= i <= j < nums.length. Then the number of distinct values in nums[i..j] is called the … Read more

[solution] Reaper Reaps solution codechef

Problem solution codechef I have no compassion, I only exist to collect the souls of the living. On Halloween, Grim Reaper wants to reap souls from houses. There are �N houses. The �i-th of them has a safety level of ��Ai​ and has ��Bi​ people living in it. The Reaper has an ability level, denoted �L. Initially, �=0L=0. When the Reaper visits a house, the following … Read more

[solution] Ghoul-icious Goodies solution codechef

Problem solution codechef Despite my ghoulish reputation, I really have the heart of a small boy. I keep it in a jar on my desk. Alice wants to give Bob some goodies, but she’s uncertain about how many to give. To help determine the quantity, she presented Bob with the following challenge: Alice has a … Read more

[solution] Spooky Sequences solution codechef

Problem solution codechef “I am not a witch. I’m your wife.” – Valerie, The Princess Bride Once upon a time, in a distant land, a mischievous witch spied on a group of people who were enjoying their time together. Enveloped by a dark desire, she resolved to put an end to their merry gatherings and … Read more

[solution] Wishcraft solution codechef

Problem solution codechef Magic is really very simple, all you’ve got to do is want something and then let yourself have it. Chadda and his Wizard friend PSC were exploring the enchanted forest on Halloween, when Chadda stumbled upon an array �A of �N magical numbers which took him into a different world. Chadda remembered that PSC gave him … Read more

[solution] Dull Operation solution codechef

Problem solution codechef Be afraid, be very afraid. On Halloween, Chef is in a somber mood. Chef has an odd integer �N that he has to decode. To do so, Chef would like to find a pair of integers �x and �y (0≤�,�<2300≤x,y<230) such that: (�∣�)⋅(�⊕�)=�(x∣y)⋅(x⊕y)=N Help Chef find any such pair! It can be proved that a valid pair always exists. Here, ∣∣ represents the bitwise OR operation, … Read more