Hi, I am getting wrong answer for krillin is dead again https://www.codechef.com/viewsolution/18909176 Can anyone say me where I am getting it wrong. Thanks in advance.
Krillin is dead AGAIN Problem
Code Chef Certification Useful for College Admission
I have passed Class X with basic knowledge of Java Code. I am willing to invest time in CodeChef competitions. Will Code Chef Certification Carry some recognition when I apply for UG Colleges (in India / Abroad) after Class XII. Pls help. Good Luck
Probable wrong testcases for the question TLG?
Hello.
I think there are some serious issues with the testcases provided in TLG.
The input instruction says :
" The first line of the input will contain a single integer N (N ≤ 10000) indicating the number of rounds in the game. Lines 2,3,...,N+1 describe the scores of the two players in the N rounds. Line i+1 contains two integer Si and Ti, the scores of the Player 1 and 2 respectively, in round i. You may assume that 1 ≤ Si ≤ 1000 and 1 ≤ Ti ≤ 1000. "
Because of the constraints i added something like this to my code,
if(N > 10000) || if(Si < 1 || Si > 1000) || if(Ti < 1 || Ti > 1000) then Exit(0);
But the compiler kept rejecting my answer returning WA. I couldn't understand what was going on and then after wasting a whole day's time when i came across link text comment by @beroul i took the test case but it gave nothing as in last line score of p2 is zero.
Afterwards, just to try my luck i removed all the input constraints from my code and it works just fine. Are we not supposed to check whether an input meets the declared constraints or not? If so, what the above quote means and how a testcase that doesnot follow the instructions was given? Or maybe i am mis-understanding something. Please point it out to me.
Any answer is much appreciated. Thank you for your time. :)
TLE in Fair Cut
can someone explain this problem in O(n*n) running time. My solution is getting TLE.
RUNDIR - Editorial
Problem Link:
Setter: Alei Reyes
Tester: Triveni Mahatha
Editorialist: Triveni Mahatha
Difficulty:
EASY MEDIUM
Prerequisites:
Binary Search, Greedy
Problem:
N students are standing at distinct points in the X-axis. Every students will start running at t = 0. assign direction (left/right) to each of them such that the first time when any two students cross each other is as large as possible. Speed of every students is given.
Quick Explanation:
Do binary search on the time. Suppose at any step in the binary search, we are are trying to find whether it is possible to assign direction such that no students will cross before some time say t.
To check, whether it is possible to assign direction. We fix the direction of leftmost students towards left (without loss of generality). For every other student from left to right, we try to fix the direction to left itself if it crosses non of the students before time t. And move to next student.
If it is not possible, we try to fix the direction as right. If it is possible then move to next student.
If we are able to assign direction to each students in that manner then the answer is yes, otherwise it is not possible.
SOLUTION:
Time Complexity:
For required precision, iterating 100 steps in the binary search is enough. Let's say the number of steps be S.
$O(S N)$ per test case.
Space Complexity:
$O(N)$
i have solved the naive chef question n i'm getting correct answer but the code is not being accepted by codechef. Can someone tell me wats wrg with my code??
include <stdio.h>
int main() { int i,j,n,t,a,b; float p=0.0,q=0.0,r=0.0; scanf("%d",&t); for(i=0;i<t;i++) {scanf("%d%d%d",&n,&a,&b); int k=(int)malloc(nsizeof(int)); for(j=0;j<n;j++) {scanf("%d",(k+j));} if(a==b) {for(j=0;j<n;j++) { if((k+j)==a) q++;
}p=((q*q)/(n*n));
}
else
{for(j=0;j<n;j++)
{
if(*(k+j)==a)
q++;
else if(*(k+j)==b)
r++;
}p=((q*r)/(n*n));
}printf("%f",p);
q=0.0;
r=0.0;
}return 0;
}
TLE in Sheokand and String(SHKSTR)
can anyone help me in this problem , i am getting TLE in task 3 . I checked up the editorial and the approach seems almost similar. can anyone help?
here is the link to my submission.
Note - In the structure Node , mn is the minimum index of the string passing through it, and x is the index of the string ending at that leaf .
so mn is ids[0] and x is leaf_id if you co-relate solution with editor.
Regarding CCDSAP scholarship and Laddus
When and how will codechef contact college toppers who will be offered 100% scholarship for CCDSAP. And, also since I landed under top 20 Indians when will I get my laddus.
I know that I should keep patience but Since it is my first time, when I will get laddus, I am little excited about this.
VSN - Editorial
Problem Link
Author:Rahim Mammadli
Tester:Misha Chorniy
Editorialist:Bhuvnesh Jain
Difficulty
EASY-MEDIUM
Prerequisites
Cross Product, Binary Search
Problem
Given a stationary point $P$ and a point $Q$ moving in straight line, indicate the time when $Q$ is visible from $P$, given that there am opaque sphere between them.
Explanation
We will try to find the solution in 2-D and then extend the idea to 3-D as well.


From the above figure, the first idea which can be clearly concluded is that, once point $Q$ becomes visible from $P$, it will remain visible forever. Before that, it will always remain invisible. This, the function (whether $Q$ is visible $P$ at given time $t$) follows the idea that it is false initially and after a certain point, it always remains true. This hints that we can binary search on the answer and just need to check whether the point $Q$ is visible from $P$ at given time $t$ or not. For more ideas on "Binary search" on such type of problem, refer to this awesome tutorial on topcoder. Hence, solution template looks like:
double low = 0, high = 10^18
for i in [1, 100]:
double mid = (low + high) / 2
if visible(P, Q, C, r, mid):
high = mid
else:
low = mid
double ans = (low + high) / 2

So, given a particular time $t$, we can first calculate the position of point $Q$. Join $P$ and $Q$ by a straight line. If the line doesn't pass through the circle, the point $Q$ is visible from $P$ else it is not visible. To check if a given line passes through the circle or not, it is enough to check that the perpendicular distance of the line from the centre, $C$, of the circle is greater than the radius, $r$, of the circle. For this, we first complete the triangle $PCQ$ and let the perpendicular distance of $PQ$ from $C$ be denoted by $CO$. Using the formula,
$$\text{Area of triangle} = \frac{1}{2} * \text{Base} * \text{Height} = \frac{1}{2} * CO * PQ$$
Since the area of the triangle can be found given 3 points in 2-D, and $PQ$ is the Euclidean distance between $P$ and $Q$, we can find the value of $CO$ efficiently. Finally, we just need to compare it to $r$, the radius of the circle.
For extending the solution in 3-D, the idea is same and we just need to find the area of a triangle in 3-D. For details, one can refer here. It can be clearly seen that the above formula holds for the 2-D case as well.
$$\text{Area of triangle in 2/3-D} = \frac{|CP X CQ|}{2}$$
where $CP$ and $CQ$ are vectors, $a X b$ denotes cross product of vectors and $|a|$ denotes the magnitude of vector.
Thus, to find the length of $CO$, we have
$$|CO| = \frac{2 * \text{Area of triangle PCQ}}{|PQ|} = \frac{|CP X CQ|}{|PQ|}$$
For more details, you may refer to the editorialist solution which exactly follows the above idea.
Extra Ideas/Caveats
The binary search implementation mentioned in the editorial is different from the one mentioned in Topcoder tutorial. Though both will give AC here, the one in Topcoder needs one to correctly set the Epsilon value for termination condition and sometimes can lead to wrong answers due to precision issues. The editorialist just prefers the above style to implement binary and ternary search involving doubles as calculation of epsilon is not required.
Note from the author
Finding the distance of a point from a line in 3-D is a generally common problem and also contains some edge cases where the point may not lie within the line segment region. But given the constraints of the problems, there are no edge cases but we should be aware of it in general.

Feel free to share your approach, if it was somewhat different.
Time Complexity
$O(1)$ per test case (around 100 iterations for binary search).
Space Complexity
$O(1)$
AUTHOR'S AND TESTER'S SOLUTIONS:
Author's solution can be found here.
Tester's solution can be found here.
Editorialist's solution can be found here.
Plagiarism Help - False Positive MOSS
First of all i would like to say, i am really sry but i am kind of worried about false positive MOSS hit i got in May18B. I totally understand codechef team is busy but it has been over 14 days since i submitted my request for restoration of rank through mail but i received no reply yet. (and i was kinda scared of ending up like this guy - https://discuss.codechef.com/questions/126366/damn-what-just-happened/126532)
According to the mail i received, the two solutions bellow were found same: https://www.codechef.com/viewsolution/18555493 (Mine) https://www.codechef.com/viewsolution/18408704 (Egors)
I would like to point out, that the solutions written by us are totally different and may have triggered the MOSS cuz of us using the same IO library (ya, i know we both didn't credit but i don't even remember where i got it from lol). A look at that those links can tell you that the time complexity of the solutions are different. (Mine is brute force and only passed 4 cases while egors passed all of them). Also, umm, the main code is totally different if you go into the main function.
At the end, i hope my ranking for May18B and solution will be restored.
Thanks
Solution for VSN giving TLE in python 3 using the editorial approach
I used the same approach as mentioned in the editorial using python 3. I am getting TLE for 6 out of 7 tasks.
The link for the code is:
Could anyone please check and see whats wrong with my code. I have been trying from many days but not able to understand why I am getting TLE. It will be of great help. Thanks!!
Need help/advice for programming
I am at that stage in programming that whenever I see a question related to trees or graphs I don't even read it and just skip it.I have no knowledge of trees or graphs but I want to learn them.I want help in how to start these topics and some problems(mostly basic) on them to gain some confidence. Can someone please help me or at least tell me the resources to start learning these topics.
Whats wrong with my code?
Link to Problem:-https://www.codechef.com/problems/VEGETA My Solution:-https://www.codechef.com/viewsolution/18911997
hackerrank graphs
Can anyone find what is mistake in my solution to the problem roads and libraries. I am getting a SIGSEGV error.
https://www.hackerrank.com/challenges/torque-and-development/forum/comments/454647
What's wrong with my code?
I am trying this problem on longest palindromic subsequence. https://www.spoj.com/problems/JEWELS/ Here is my code- https://pastebin.com/sDKrqg5g I am unable to find the bug.Kindly help.Kindly tell how to approach this problem,how to calculate the center of the longest palindromic subsequence
the following code does not insert 2nd element ?why>
void insertFirst(int d){ Node* temp=new Node(); temp->data=d; temp->next=head; head=temp; }
Krillin is dead AGAIN Problem Code
Can i get correct value of medium using this formula: 3median = 2mean + mode.
Or i have to explicitly figure out through element wise compare.
BINSHFFL - Editorial
Problem Link
Author:Noszály Áron
Tester:Misha Chorniy
Editorialist:Bhuvnesh Jain
Difficulty
EASY
Prerequisites
BFS/Floyd Warshall, Observations
Problem
You are to convert number $A$ to number $B$ using the following operation in the minimum number of steps:
- Write A as a binary number with arbitrary number of leading zeros (possibly none)
- Shuffle the binary digits of the A in an arbitrary order. Call it $A'$
- The output is $(A' + 1)$. Let us call this number as $X$.
Remember the notation of $A'$ and $X$ as it is used everywhere in the editorial.
Explanation
Subtask 1: A, B ≤ 128
The problem asks to minimise the number of steps to go from $A$ to $B$. Generally, these type of problems can be easily modelled as a graph and perform BFS to find the answer. Here is a general idea:
Let us model each step as an edge from initial number to final number with an edge of some cost. So, the path with the smallest weight from source to destination is the required answer and also gives us a way to achieve the transition.
In this problem, we can just do what the operations ask us to do. Just all possible shuffling of the digits of A in binary representation and consider only those ones which give end result within the desired range ([0, 128]). Let us call this number as $X$. Add an edge of weight $1$ from $A$ to $X$. Build the complete graph based on all possible transitions. Make sure that this graph will be directed one as transforming from $A$ to $X$ might not be the same as transforming from $X$ to $A$ due to the last operation which adds $1$ to the result. Once, we have the directed graph, we can simply perform any all pair shortest path algorithm like BFS, Floyd Warshall (or Dynamic Programming as a graph is directed) and precalculate the answer for all possible cases. Once, the answers are precalculated, each test case can be answered in constant complexity. For more details, one can refer to the editorialist solution below.
The maximum number of edges from a number $A$ emerging out will be $7! = 5040$ in the worst case, but in practice, it will be quite less. The number of vertices in the graph will be $128$. Using Floyd Warshall algorithm the precomputation can be achieved in $O(128^3)$, i.e. $O(A^3)$. This is enough to solve this subtask.
Subtask 2: A, B ≤ ${10}^{18}$
The constraints in this subtask are quite large and the number of test cases also suggest we need a logarithmic approach. This leads us to write $A$ and $B$ in binary representation and finding some observations to proceed with the solution.
Let us first simplify the approach by trying to convert $A$ to $(B-1)$ as in the end $1$ would be added as part of the last operation.
We can see that in one step we can shuffle the digits of $A$ in such a manner that an extra $1$ is introduced in the binary representation of the newly formed number. This can be done by simply shuffling the digits to contain binary digit $1$ from the ${2}^{nd}$ position. For example: Let $A = 3$. In binary representation $A = 011$. We can shuffle the digits as $A' = 110$. On adding $1$, we get $X = 111$, i.e. $X = 7$. Thus, we can introduce a binary digit $1$ in one step.
Also, we can decrease any number of binary digit $1$ from $A$. This can be done by easily placing the required in the number of $1$ in towards the end, followed by a $0$ and then placing the digits in any order we like. For example: Let $A = 13$, i.e. $A = 1101$ in binary representation. Say we want to decrease one binary digit $1$, we can arrange the digits as $A' = 1011$. On adding $1$, we get $X = 1100$. If we wanted to decrease two binary digit $1$, we can arrange the digits as $A' = 0111$. On adding $1$, we get $X = 1000$. Thus, we decrease any number of binary digit $1$ in one step.
With the above 2 scenarios, the following is the algorithm-
- Find the number of ones in the binary representation of $A$ and $(B - 1)$. Let us denote then by $OA$ and $OB$
- If $OA > OB$, then we can achieve the operation in $2$ steps. First decreasing the number of ones in the first step and then rearranging the digits in another step.
- If $OA <= OB$, then we need $(OB - OA)$ steps to first make the number of ones equal (see decrease operation takes place at one step each). Finally, we can arrange the digits to achieve the desired number.
The only corner case is as follows:
- If $B$ is $0$ then, we can't achieve the desired state whatever the value of $A$ is. Since we are adding $1$ in the last step we are guaranteed to have atleast one binary digit $1$ in binary representation. Thus the answer for this case is $-1$.
- If $B$ is $1$ then, we can achieve the desired state only if $A = 0$, in one step. In another case, it is impossible as even though decreasing the number of binary digit $1$, the end result would be a number greater than $1$. So the answer is $1$ if $A = 0$, else $-1$.
The number of ones in binary representation can be calculated using the below pseudo-code:
def count_ones(integer x):
ones = 0
while x > 0:
if x % 2 == 1:
ones += 1
x /= 2
return ones
Feel free to share your approach, if it was somewhat different.
Time Complexity
$O(\log{A} + \log{B})$ per test case.
Space Complexity
$O(1)$
AUTHOR'S AND TESTER'S SOLUTIONS:
Author's solution can be found here. (It will pass subtask 1 only and uses dynammic programming approach)
Tester's solution can be found here.
Editorialist's solution for subtask 1 can be found here.
Editorialist's solution for full problem can be found here.
why showing runtime error
T= int(input()) for i in range(T): n= int(input())
s=input().split()
count = 0
what = 0
for i in s:
if i == s[0] :
count=count+1
elif i == s[1]:
what = what+1
if count==what :
print('Draw')
elif count>what :
print(s[0])
else :
print(s[1])