[Solution] Non Zero Xor solution codechef

Non Zero Xor solution codechef – An array AA of size NN is called good if the following conditions hold: For every pair (l, r)(l,r) (1 \le l \le r \le N)(1≤l≤r≤N), A_l \oplus A_{l+1} \oplus … \oplus A_{r} \ne 0Al​⊕Al+1​⊕…⊕Ar​=0. (where \oplus⊕ denotes the bitwise XOR operation.) [Solution] Non Zero Xor solution codechef JJ has an array AA of size NN. He wants to convert the array to … Read more

[Solution] OR Tuples solution codechef

OR Tuples solution codechef – Chef has 33 numbers PP, QQ and RR. Chef wants to find the number of triples (A, B, C)(A,B,C) such that: (A \mid B) = P,(A∣B)=P, (B \mid C) = Q(B∣C)=Q and (C \mid A) = R(C∣A)=R (Here, \mid∣ denotes the bitwise OR operation) 0 \le A, B, C \lt 2^{20}0≤A,B,C<220 [Solution] OR Tuples solution codechef Can you help Chef? Input Format The first … Read more

[Solution] Balls and Boxes solution codechef

Balls and Boxes solution codechef – You have NN balls and KK boxes. You want to divide the NN balls into KK boxes such that: Each box contains \ge 1≥1 balls. No two boxes contain the same number of balls. [Solution] Balls and Boxes solution codechef Determine if it is possible to do so. Input Format The first line contains a single integer TT — the … Read more

[Solution] Mean and Median solution codechef

Mean and Median solution codechef – Chef has two numbers XX and YY. Chef wants to find three integers A, B,A,B, and CC such that: -1000 \le A, B, C \le 1000−1000≤A,B,C≤1000 mean([A, B, C]) = Xmean([A,B,C])=X median([A, B, C]) = Ymedian([A,B,C])=Y [Solution] Mean and Median solution codechef Can you help Chef find such three integers? As a reminder, mean([P, Q, R]) … Read more

[Solution] Permutation Clear solution codechef

Permutation Clear solution codechef – Alice has an array AA of length NN which is initially a permutation. She dislikes KK numbers which are B_1, B_2, \ldots, B_KB1​,B2​,…,BK​ all of which are distinct. Therefore, she removes all the occurrences of these numbers from AA. The order of the remaining elements of the AA does not change. [Solution] Permutation Clear solution codechef Can you find out the resulting array AA? Note: … Read more

[Solution] Fever solution codechef

Fever solution codechef – Chef is not feeling well today. He measured his body temperature using a thermometer and it came out to be XX °F. A person is said to have fever if his body temperature is strictly greater than 9898 °F. [Solution] Fever solution codechef Determine if Chef has fever or not. Input Format The first line contains … Read more

[Solution] Area Sums in Convex Polygons solution codechef

Area Sums in Convex Polygons solution codechef – You are given a convex polygon PP with NN vertices. The vertices (in clockwise order) are v1,v2,…vNv1,v2,…vN. The coordinates of vivi are (xi,yi)(xi,yi). All vertices have integer coordinates. A diagonal of PP is a line segment ll joining two distinct vertices vivi and vjvj of PP, such that ll is not already an edge of PP. Every diagonal of PP splits it into two smaller convex polygons, both having positive areas. The evenness of a diagonal … Read more

[Solution] Sequence GCD solution codechef

Sequence GCD solution codechef – You are given an integer sequence A=(A1,A2,…,AN)A=(A1,A2,…,AN) of length NN and an integer MM such that 0≤M<∑i=1NAi0≤M<∑i=1NAi. An integer sequence B=(B1,B2,…,BN)B=(B1,B2,…,BN) of length NN is called good if: 0≤Bi≤Ai0≤Bi≤Ai for each 1≤i≤N1≤i≤N B1+B2+⋯+BN=MB1+B2+⋯+BN=M Find the maximum value of gcd(A1−B1,A2−B2,…,AN−BN)gcd(A1−B1,A2−B2,…,AN−BN) over all good sequences BB. Here, gcdgcd denotes the greatest common divisor. Note: gcd(a,b,c)=gcd(a,gcd(b,c))gcd(a,b,c)=gcd(a,gcd(b,c)) and gcd(a,0)=gcd(0,a)=agcd(a,0)=gcd(0,a)=a. Sequence GCD solution codechef The first line of input contains a single integer TT, denoting the number of test cases. The … Read more