Coding

Coding

Half Sequence Solution Codechef september cook off 2021

Half Sequence Solution Codechef september cook off 2021 Chef has an array AA of size NN. Chef wants to choose any subsequence of size exactly ⌈N2⌉⌈N2⌉ from the array such that GCD of all the elements in that sequence must be 22. Chef names such a kind of sequence as a half-sequence. Help Chef to find whether he would be able to select …

Half Sequence Solution Codechef september cook off 2021 Read More »

Chef and Pairwise Distances Solution Codechef september cook off 2021

Chef and Pairwise Distances Solution Codechef september cook off 2021 Chef has an array AA with NN elements. He wants to find NN points P1,…,PNP1,…,PN with integer coordinates on the 2D coordinate plane such that, for all pairs of indices ii and jj (1≤i<j≤N1≤i<j≤N), the Manhattan distance from PiPi to PjPj is Ai+AjAi+Aj. Help him find any NN points satisfying the condition, or state that no such points exist. As a reminder, the Manhattan distance between …

Chef and Pairwise Distances Solution Codechef september cook off 2021 Read More »

Fake Swaps Solution Codechef september cook off 2021

Fake Swaps Solution Codechef september cook off 2021 You are given two binary strings SS and PP. You need to convert SS into PP using the following operation any number of times (possibly zero): Pick three binary values XX, YY, and ZZ, such that at least one of them is equal to 11 and at least one of them is equal to 00. Then, pick three distinct indices ii, jj, …

Fake Swaps Solution Codechef september cook off 2021 Read More »

Zebra Crossing Solution Codechef september cook off 2021

Zebra Crossing Solution Codechef september cook off 2021 There’s a zebra crossing appearing in the middle of nowhere with NN blocks in it. The colors of the zebra crossing is represented by a binary string SS, where SiSi is 1 if the ii-th block from the left is white, and 0 if the block is black. Chef really wants to play with the zebra crossing. …

Zebra Crossing Solution Codechef september cook off 2021 Read More »

Adjacency Hatred Solution Codechef september cook off 2021

Adjacency Hatred Solution Codechef september cook off 2021 An array is called lovely if the sum of absolute differences of each adjacent pair of elements is odd; formally, the array SS of size mm is lovely if ∑m−1i=1∑i=1m−1 |Si−Si+1||Si−Si+1| is odd. You are given an array AA of NN integers. You need to reorder the array in any manner such that the array becomes lovely. If there is …

Adjacency Hatred Solution Codechef september cook off 2021 Read More »