This Question is from foundation CCDSAP from binary search: https://www.codechef.com/problems/DIVSET
My solution: https://www.codechef.com/viewsolution/22866957
This Question is from foundation CCDSAP from binary search: https://www.codechef.com/problems/DIVSET
My solution: https://www.codechef.com/viewsolution/22866957
I can see few codechef discuss links regarding the questions. But when I try to click on them, it gives me error 404. These are the questions I have mentioned above.
https://discuss.codechef.com/questions/144901/chef-and-magical-jars-problemhttps://discuss.codechef.com/questions/144924/chef-and-magical-jars
Please tell me the problem bcoz program is doing what was asked in problem.
int main(void) { int T,N,u=0,j,k; scanf("%d",&T); for(j=0;j<t;j++) {="" scanf("%d",&n);="" int="" s[n];="" for(k="0;k<N;k++)" scanf("%d",&s[k]);="" for(k="0;k<N;k++)" {if(k="=0&&s[k+1]==0&&s[k]==0)" {u+="1;s[k]=1;}" else="" if(k="">0&&k<N-1) {if(s[k-1]==0&&s[k+1]==0&&s[k]==0) {u+=1;s[k]=1; }} else if(k==N-1) if(s[k-1]==0&&s[k]==0) {u+=1;s[k]=1;} } printf("%d \n",u);u=0; } return 0; }
Hi,
It seems there is some error in calculating absolute scores for Feb19 challenge problem CHORCKIT. In the problem statements we have: "The length of the string S must not exceed 10^6 at any time.", "There are M melodies ... M <= 100", "Ci <= 1000". So even if every pretty melody occurs at every position in the resulting string and every melody has the maximal possible pretty value, we can get at most V = 10^6 * 100 * 1000 = 10^11 for each test. Now, the absolute score is V/100, i.e. no more than 10^9 for each test or 5*10^9 for 5 tests.
However currently the best solution shows some astronomic numbers like 22271556114636.004. And what is .004 while we are dividing integer value by 100? Is this just a float-precision issue? I asked about score values in the problem comments about 20 hours ago, but have no answer still.
Hi there,
What do to when the comments are not being answered during live contest?
I have been waiting for answer from 3-4 hour and no replied had came.
I have doubt in MANRECT problem.
Please help.
:(
i am interested in python. now i want to learn machine learning with python...
We have to find the sum of the sum of digits of a very long integer.
Author:Ankush Khanna
Easy
Given an $N \times M$ grid, filled with integers, find the largest connected area (side adjacent elements) filled with same numbers. If there are more than one such connected areas, find the one filled with the minimum number. Print the Value and Area of that region.
Key to AC: Run a Depth First Search on the elements of the grid to find the various connected components, and then just find the one with maximum elements connected, if there are more than one such areas, find the one with minimum number written on them.
To solve this problem, one needs to know about what connected components are. And the best approach would be a DFS through the grid to find all connected components in this grid (connected in a sense that same elements which are side adjacent are parts of one single component). To find the region with the maximum number of elements is just an added task here, we just need to keep a track of it, that's it. Moreover, finding the region with largest area (number of elements) and having the least possible element value if there exist more than one regions with the maximum area, is another added task.
Almost all the solutions that achieved only 30 points (sub-task 1), either missed on some edge cases, failed to keep track of optimal region correctly, or were unable to control recursion for their recursive DFS implementation (improper user of the visited nodes).
This problem can easily be solved in $O(N \times M)$ time with $O(N \times M)$ auxiliary space for keeping a track of the visited nodes, just to control excessive recursion (for recursive approaches) or excessive searching (for iterative approaches).
This problem is very similar to the Number of Islands problem, the difference here is just that here we need to keep a track of the area and value involved for a particular region found. Also, a similar problem is the Largest Region problem.
$O(N \times M)$ time with $O(N \times M)$ auxiliary space.
Number of Islands Problem
Largest Region Problem
Two Flowers (This one is way more complex because it involves DSU, as we can have at most two different numbers in a region, a very good problem to practice).
Feel free to share your approach. If you have any queries, they are always welcome.
Author:Full nameTester:Full nameEditorialist:Oleksandr Kulkov
SIMPLE
Basic xor properties
You need to guess sequence of number $a_1,\dots,a_N$ ($8 \leq N\leq 5 \cdot 10^4$). You're allowed to ask $N$ queries of kind calculate $a_i \oplus a_j \oplus a_k$ for three distinct indices $i,j,k$ where $\oplus$ is bitwise xor operation. Additionally each index may appear in queries at most $3$ times.
Solve $N=3k+1$ and $N=3k+2$, then due to constraints $N=3k$ may be decomposed into $N=4$ and $N=3(k-2)+2$.
Consider quadruple $a_1,a_2,a_3,a_4$. We may only ask four queries for it, we'll see that it's enough:
$$\begin{cases} a_1 \oplus a_2 \oplus a_3 = b_1 \\ a_1 \oplus a_2 \oplus a_4 = b_2 \\ a_1 \oplus a_3 \oplus a_4 = b_3 \\ a_2 \oplus a_3 \oplus a_4 = b_4 \end{cases} $$
Given that $x \oplus x \oplus x = x$ we may obtain that $a_1 \oplus a_2 \oplus a_3 \oplus a_4 = b_1 \oplus b_2 \oplus b_3 \oplus b_4$. Thus solution to the system is: $$\begin{cases} a_1 = b_1 \oplus b_2 \oplus b_3 \\ a_2 = b_1 \oplus b_2 \oplus b_4 \\ a_3 = b_1 \oplus b_3 \oplus b_4 \\ a_4 = b_2 \oplus b_3 \oplus b_4 \end{cases} $$
in this way we may resolve any quadruple. But we also may see that there is another interpretation of equations we get for quadruple. From one point of view we consider every way to leave one variable out. This approach is not feasible for higher $N$. But we also may see it as we consider every possible way to take $3$ consecutive variables in the xor. And this approach is feasible!
Let's consider $N$ xor triples $b_i = a_{i-1} \oplus a_{i} \oplus a_{i+1}$ with $a_{N+1} \equiv a_1$ and $a_{-1} \equiv a_N$. Let $s = b_1 \oplus \dots \oplus b_N$. One can see that for this value holds $s=a_1 \oplus \dots \oplus a_{N}$ since all $a_i$ occur in $s$ exactly thrice. Now we should consider cases:
Combining this approaches as mentioned in quick explanation will finish off the problem. Note that due to $N \leq 5 \cdot 10^4$ you'll have to use some kind of prefix and suffix sums grouped by remainder of index modulo $3$ to quickly calculate final values of $a_i$.
Author's solution can be found here.
Tester's solution can be found here.
I don't know why my code for the problem https://www.codechef.com/problems/EGRANDR is giving partially correct answer .Please help me .My code :https://ideone.com/HmkDrP . Thanks in advance.
How to know whether a character is present in two different words or not? Like "o" is present in both words "boy" and "toy".How will I print it.
How to know whether a character is present in two different words or not? Like "o" is present in both words "boy" and "toy".How will I print it.
Hi,
What can be the reasons of getting WA In Interactive Problems?
I think my logic is correct regarding question but I am getting WA WA and WA .
I wonder can there be another reasons of getting WA.
Can you tell me what problems you had faced while solving problems with silly mistakes.
Please share what king of mistakes you had made earlier
Please also share what kinds mistakes can anyone make
Thank's in advance
Can anyone plz explain this question??
exactly how much time codechef takes for processing laddus of a contest ??
can someone give me a upper bound :D
Till when January challenge laddus will be given
I want to know why it happens with me many a times that my solutions give right output but I still get a WA ? For example , for this question https://www.codechef.com/FEB19B/problems/DEPCHEF . My solution was giving the right output , but a WA . I can give the link to my solution here , if allowed .
Hi, I'm looking for objects from an application area to train an SVM. I've been thinking for some time which objects are suitable, because I would not use images from fish or butterflies.
Does anybody have an interesting idea? Above all, objects would be in demand, which differ particularly because of their geometry.
Thanks in advance for every tip.
Author:Ankush Khanna
Easy-Medium
AM-GM Inequality, Modular Arithmetic, Modular Inverse, Fast Exponentiation, Fermat's Little Theorem, Mathematics
Given the size $N$ of a sequence of numbers, and the sum $S$ of that sequence, find the maximum product of this sequence, and print it modulo ($10^9 + 7$).
Key to AC: The answer to this problem is $((\frac {S} {N})^N \bmod (10^9 + 7)) \space$, using AM-GM Inequality. Here, using modular arithmetic, we can find the modular inverse of $N^N \bmod (10^9 + 7) \space$, using techniques like Fermat's Little Theorem and then do modular multiplication with $S^N \bmod (10^9 + 7)$. Everything is explained in detail in the explanation part.
Let's first see what all Mathematics we need to know in order to solve this problem. Let's, for the sake of comfort, name the sequence as $A$. First of all, let me state the problem mathematically,
Now, first understand what AM-GM inequality is, and why is it important here. It is stated mathematically as:
Also, one needs to understand that $integers$ are different from $numbers$. $Numbers$ can be anything. They can be $integer$, $fraction$, $irrational$, $real$, $complex$, etc. But, here, it can be proved that $P$ is always a rational number and can be expressed in the form of $\frac {X} {Y}, \space Y \neq 0$ and both $X$ and $Y$ are positive $integers$. It is very clear here, we don't even need to explicitly prove it, it can be seen easily in our derived expression for $P$. [Integers and Numbers]
Now, it is mentioned that we need to print the answer modulo $10^9 + 7$ (smallest 10 digit prime number). Therefore, we need to do something like:
A basic understanding of modular arithmetic is a must for this problem. One must be clear about the rules of modular arithmetic, before attempting this problem.
We can easily do modular exponentiation in $O(\log_2 N)$ time complexity. We can easily find the Modular Inverse of $N^N$ using Fermat's Little Theorem in $O(\log_2 M)$ time, where $M$ is a prime and $M = 10^9 + 7$. And, it can also be proved that, $gcd(N^N, \space M) = 1$, as $N \lt M$, and $M$ is a prime, $\therefore \space N^N$ can never have any common divisor with $M$, which is a mandatory condition for modular multiplicative inverse to exist and be unique.
Sub-Task 1
It is given than $S = \alpha \times N$, where $\alpha$ is a positive $integer$.
$\implies \space$ We don't need to find the modular inverse, $\because \space \alpha = \frac {S} {N}$, so just printing $(\alpha^N \bmod (10^9 + 7)) \space$ will get you 10 points. Time taken per test case would be $O(\log_2 N)$ with $O(1)$ auxiliary space.
Sub-Task 2
Can be solved as mentioned above in the explanation part.
Final Result = $(S^N \bmod M) \times ((N^N \bmod M)^{(M - 2)}) \bmod M$, where $M = (10^9 + 7)$
$\{$According to Fermat's Little Theorem, $modularInverse(X) \mod Y = X^{(Y - 2)} \bmod Y\}$
$O(\log_2 N + \log_2 M)$ time per test case, where $M = 10^9 + 7$, with $O(1)$ auxiliary space used.
$\therefore$ total time for each test file would be $O(T \times (\log_2 N + \log_2 M)) \space$, which would suffice our time constraint.
Feel free to share your approach. If you have any queries, they are always welcome.