Codechef

Chodechef long challenge problems

Chef and Pairs | PAIRCNT | CODECHEF JULY CHALLENGE

View problem on codechef You are given a tree (connected, undirected, acyclic graph) consisting of NN nodes. Based on this tree, you have to answer QQ queries. Each query is of the form: K D V1 V2 ⋯ VKK D V1 V2 ⋯ VK – output the number of pairs (i,j)(i,j), 1≤i<j≤K1≤i<j≤K, such that the shortest path between nodes ViVi and VjVj in the tree has DD edges. Input The first line contains an integer TT, the number of …

Chef and Pairs | PAIRCNT | CODECHEF JULY CHALLENGE Read More »

K Path Query Solution | KPATHQRY | CODECHEF JULY CHALLENGE

View problem on codechef You’re given a tree with NN vertices numbered from 11 to NN. Your goal is to handle QQ queries. For each query you are given KK nodes v1,v2,…,vKv1,v2,…,vK. Find if there exists a simple path in the tree covering all the given vertices. Input The first line contains a single integer TT – the number of test cases. The description of TT test cases follows. …

K Path Query Solution | KPATHQRY | CODECHEF JULY CHALLENGE Read More »

Chef vs Bharat Solution | CHEFORA |CODECHEF JULY CHALLENGE

View problem on codechef Chef and his friend Bharat have decided to play the game “The Chefora Spell”. In the game, a positive integer NN (in decimal system) is considered a “Chefora” if the number of digits dd is odd and it satisfies the equationN=∑i=0d−1Ni⋅10i,N=∑i=0d−1Ni⋅10i, where NiNi is the ii-th digit of NN from the left in 00-based indexing. Let AiAi denote the ii-th largest Chefora number. They’ll ask each …

Chef vs Bharat Solution | CHEFORA |CODECHEF JULY CHALLENGE Read More »

XxOoRr Solution | XXOORR | CODECHEF JULY CHALLENGE

View problem on codechef Given an array A1,A2…ANA1,A2…AN, find the minimum number of operations (possibly zero) required to convert all integers in AA to 00. In one operation, you choose a non-negative integer pp (p≥0p≥0), select at most KK indices in the array AA, and for each selected index ii, replace AiAi with Ai⊕2pAi⊕2p. Here, ⊕⊕ denotes bitwise XOR. Input The first line contains an integer TT – the number of test …

XxOoRr Solution | XXOORR | CODECHEF JULY CHALLENGE Read More »

Relativity | RELATIVE | CODECHEF JULY CHALLENGE Solution

View problem on codechef In Chefland, the speed of light is c m/sc m/s, and acceleration due to gravity is g m/s2g m/s2. Find the smallest height (in meters) from which Chef should jump such that during his journey down only under the effect of gravity and independent of any air resistance, he achieves the speed of light and verifies Einstein’s …

Relativity | RELATIVE | CODECHEF JULY CHALLENGE Solution Read More »

CODECHEF: JUNE CHALLENGE | MFSS | PYTHON, JAVA, C++ SOLUTION

View problem on codechef Akash has just learned the maximum subarray sum problem. And while thinking about the solution, he came up with a new problem, the maximum frequent subarray sum problem. In this problem, you will be given an array AA of NN integers. You have to choose a non-empty subarray with the maximum possible score. The score of a subarray is …

CODECHEF: JUNE CHALLENGE | MFSS | PYTHON, JAVA, C++ SOLUTION Read More »

CODECHEF: JUNE CHALLENGE | MathBuzz | PYTHON, JAVA, C++ SOLUTION

View problem on codechef There is an inter-city math competition among kk various prestigious top schools in the city. Some subset of schools will be selected to compete, where the ii-th school is selected with probability pi(mod998 244 353)pi(mod998 244 353). The schools are all selected independently from each other. It’s even possible that the number of selected schools will be 00 or 11, because the …

CODECHEF: JUNE CHALLENGE | MathBuzz | PYTHON, JAVA, C++ SOLUTION Read More »

CODECHEF: JUNE CHALLENGE | Dual Distance | PYTHON, JAVA, C++ SOLUTION

View problem on codechef Given a tree with NN nodes, answer QQ queries of the following type: a,ba,b (where a≠ba≠b) which asks you to calculate ∑Ni=1min(dist(i,a),dist(i,b))∑i=1Nmin(dist(i,a),dist(i,b)) where dist(x,y)dist(x,y) is the number of edges on the shortest path between the nodes xx and yy in the tree. Note: The input and output of this problem are large, so prefer using fast input/output methods. Input The first line contains an integer TT, the …

CODECHEF: JUNE CHALLENGE | Dual Distance | PYTHON, JAVA, C++ SOLUTION Read More »

x