Strong Elements solution codechef

Strong Elements solution codechef Chef has an array AA of length NN. An index ii is called strong if we can change the gcd of the whole array just by changing the value of AiAi. Determine the number of strong indices in the array. Input Format First line will contain TT, number of test cases. Then the test cases follow. First line of each test case contains an …

Strong Elements solution codechef Read More »

Ambiguous Dominoes solution codeforces

Polycarp and Monocarp are both solving the same puzzle with dominoes. They are given the same set of n dominoes, the i-th of which contains two numbers xi and yi. They are also both given the same m by k grid of values aij such that ⋅=2m⋅k=2n. Ambiguous Dominoes solution codeforces The puzzle asks them to place the n dominoes on the grid in such a way that none of …

Ambiguous Dominoes solution codeforces Read More »

Dearrange sorting solution codechef

Dearrange sorting solution codechef You are given a permutation PP of length NN. A permutation of length NN is an array where every element from 11 to NN occurs exactly once. You must perform some operations on the array to make it sorted in increasing order. In one operation, you must: Select two indices LL and RR (1≤L<R≤N)(1≤L<R≤N) Completely dearrange the subarray PL,PL+1,…PRPL,PL+1,…PR A dearrangement of an array AA is any permutation BB of AA for which Bi≠AiBi≠Ai for …

Dearrange sorting solution codechef Read More »

Is this priority or parity! solution codechef

Is this priority or parity! solution codechef NN integers 1,2,3,…N1,2,3,…N are placed on a circle in clockwise order such that ii and (i+1)(i+1) are adjacent for all 1≤i≤N−11≤i≤N−1, and 11 and NN are also adjacent. Given an integer KK, Ashish repeatedly removes integers from the circle until only one integer remains. He does so in the following manner. In each move, Ashish finds the integer which is on …

Is this priority or parity! solution codechef Read More »

Path Parity solution codechef

Path Parity solution codechef You are given an integer NN. Let AA be an N×NN×N grid such that Ai,j=i+N⋅(j−1)Ai,j=i+N⋅(j−1) for 1≤i,j≤N1≤i,j≤N. For example, if N=4N=4 the grid looks like: Path Parity solution codechef You start at the top left corner of the grid, i.e, cell (1,1)(1,1). You would like to reach the bottom-right corner, cell (N,N)(N,N). To do so, whenever you are at cell (i,j)(i,j), you can move …

Path Parity solution codechef Read More »

Equal Integers solution codechef

Equal Integers solution codechef Chef has two integers XX and YY. Chef wants to perform some operations to make XX and YY equal. In one operation, Chef can either: set X:=X+1X:=X+1 or set Y:=Y+2Y:=Y+2 Find the minimum number of operations required to make XX and YY equal. Input Format The first line contains a single integer TT — the number of test cases. Then the test cases follow. The first …

Equal Integers solution codechef Read More »

Determine the Winner solution codechef

Determine the Winner solution codechef There is a contest containing 22 problems AA and BB. 22 strong participants PP and QQ participated in the contest and solved both the problems. PP made AC submissions on problems AA and BB at time instants PAPA and PBPB respectively while QQ made AC submissions on problems AA and BB at time instants QAQA and QBQB. It is given that the time penalty is the minimum time instant at which a participant has solved both the problems. …

Determine the Winner solution codechef Read More »

Chef and Chocolates solution codechef

Chef and Chocolates solution codechef Chef has XX 5 rupee coins and YY 10 rupee coins. Chef goes to a shop to buy chocolates for Chefina where each chocolate costs ZZ rupees. Find the maximum number of chocolates that Chef can buy for Chefina. Input Format The first line contains a single integer TT — the number of test cases. Then the test cases follow. …

Chef and Chocolates solution codechef Read More »