[SOLUTION] Reach Anywhere SOLUTION CODECHEF

Problem SOLUTION CODECHEF You are given a simple undirected graph with �N vertices and �M edges. Find the smallest non-negative integer �K such that for every vertex �u (1≤�≤�1≤u≤N), there exists a walk of length exactly �K from 11 to �u. If no such integer exists, print −1−1 instead. Notes: It is allowed to repeat both vertices and edges in a walk. The length of a walk equals the number of edges in it. Input … Read more

[SOLUTION] Save People SOLUTION CODECHEF

Problem SOLUTION CODECHEF Chef has a 22-D grid with �N rows and �M columns. The cell at the intersection of the �i-th row and �j-th column is denoted cell (�,�)(i,j). Initially, only cell (�,�)(x,y) of the grid is infected. Chef can select exactly one non-infected cell and vaccinate it. Then, the infection and the vaccine spread across the grid, as follows: First, any cell that is neither vaccinated nor infected, but … Read more

[SOLUTION] Guess the winner! SOLUTION CODECHEF

Problem SOLUTION CODECHEF Alice and Bob play a game. They start with the integer �N and take turns, with Alice going first. On their turn, a player must select an odd prime factor �p of �N, and subtract it from �N (so �N changes to �−�N−p). The player who cannot make a move loses (that is, if either �=0N=0 or �N has no odd prime factors). If Alice and Bob … Read more

[SOLUTUON] Playing with OR Solution Codechef

Problem Solution Codechef You are given an array �A containing �N integers, and an integer �K (1≤�≤�1≤K≤N). Find the number of subarrays of �A with length �K whose bitwise OR is odd. Note: A subarray of �A is a contiguous segment of elements of �A. For example, if �=[1,3,2]A=[1,3,2], then it has 66 non-empty subarrays: [1],[3],[2],[1,3],[3,2],[1,3,2][1],[3],[2],[1,3],[3,2],[1,3,2]. In particular, [1,2][1,2] is not a subarray of �A. Input Format The first line of input will contain a single integer �T, denoting the number of test … Read more

[SOLUTIUON] Chef Fantasy 11 Solution Codechef

Problem Solution Codechef   All of Chef’s friends are playing fantasy cricket based upon the ODI World Cup, and Chef would like to join them. For a certain cricket match, Chef has decided upon his team of 1111 players. However, he hasn’t yet decided who should be the captain and who should be the vice-captain. He’s narrowed … Read more

[solution] A Growing Tree Solution Codechef

F. A Growing Tree Solution Codechef time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a rooted tree with the root at vertex 11, initially consisting of a single vertex. Each vertex has a numerical value, initially set to 00. There are also q� queries of two … Read more

[Solution] E. Brukhovich and Exams Solution Codeforces

E. Brukhovich and Exams Solution Codeforces time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The boy Smilo is learning algorithms with a teacher named Brukhovich. Over the course of the year, Brukhovich will administer n� exams. For each exam, its difficulty ai�� is known, which is a non-negative integer. … Read more

[SOLUTION] Suspicious logarithms Solution Codeforces

Suspicious logarithms Solution Codeforces time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Let f�(x�) be the floor of the binary logarithm of x�. In other words, f�(x�) is largest non-negative integer y�, such that 2y2� does not exceed x�. Let g�(x�) be the floor of the logarithm of x� with base f�(x�). In other words, g�(x�) is … Read more

[Solution] Smilo and Monsters solution codeforces

Smilo and Monsters solution codeforces time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A boy called Smilo is playing a new game! In the game, there are n� hordes of monsters, and the i�-th horde contains ai�� monsters. The goal of the game is to destroy all the monsters. To … Read more

[Solution] Deja Vu Solution codeforces

Deja Vu 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 a� of length n�, consisting of positive integers, and an array x� of length q�, also consisting of positive integers. There are q� modification. On the i�-th modification (1≤i≤q1≤�≤�), for each j� (1≤j≤n1≤�≤�), such that aj�� is divisible by 2xi2��, you add 2xi−12��−1 to aj��. Note … Read more