### Nightmare05's blog

By Nightmare05, history, 12 months ago, Hi guys,

I would like to thank all participants for making this event a grand success and specially thank Journey_Begin, darklight13, se7enth_hea7en, kunj017, samraj2k, Gauri_Jain and hackcyborg for the problem setting and testing efforts and specially for actively managing the queries during contest!!

So, without wasting more time I'd like to congratulate our winners:

Based on the leaderboards following people have qualified for prizes:

Overall top 3:

Top 5 Indians:

Top 2 from IIT Patna(presently studying):

Winner from 1st year IIT Patna

## Editorals!

### Is It Some Space Cakewalk?

Problem Author: darklight13

The main idea for problem was pigeon-hole principle i.e in worst case we pick all the different type of cakes first and then any additional cake would make a pair repeat. So the answer to the problem was number of different types of cake in the list + 1.

Time Complexity O(n+max(T)).

Author Solution

### Kunj Destroys Asteroids in 13th Dimension

Problem Author: darklight13

This problem can be solved in many ways like prefix sum , window sliding or even binary search.

I will discuss one with partial sum. The equation of the rhombus can be represented by |x| + |y| = X. Thus we only need the manhattan distance of the points. We make a prefix array that will store number of points less than or equal to manhattan distance i for each i. We calculate the points lying between X and X+K using prefix sum for each X where X is prime which can be computed by sieve. For each X the number of points lying between the rhombi would be pre[X+k] — pre[X-1]. Maximum of all such iterations will be the answer.

Author Solution

### 1-2-3 Subsequence

Problem Author: samraj2k

The naive solution of iterating from l to r for each query will give TLE. Thus we use segment tree. At each node in the segment tree we store 6 values. 1. Length of maximum subsequnce strating from 1 and containing only 1. 2. Length of maximum subsequnce strating from 2 and containing only 2. 3. Length of maximum subsequnce strating from 3 and containing only 3. 4. Length of maximum subsequnce strating from 1 and containing only 1 and 2. 5. Length of maximum subsequnce strating from 2 and containing only 2 and 3. 6. Length of maximum subsequnce strating from 1 and containing only 1, 2 and 3. Now when building the segment tree you can maximize these values at each node to get the answer. At each node combine when with possible combinations like 1+(2-3), (1-2)+3, 1+(1-2), (1), (2), (3), (1-3)+3, 1+(1-3). The answer to each query will be the maximum of the above values. This can be better understood in editorial code. A much clean solution can be: https://codeforces.com/blog/entry/71357?#comment-558146 Thanks to pshishod2645

Author Solution

### Universe is random, but is it?

Problem Author: Nightmare05

First off, we begin by observing that since average of a child is his average over all exams he appears in, the expected score of a child is independent of E (the number of exams he appears in) and by a similar argument the answer is independent of N (number of students) as well. So, we know that answer is a function of M (maximum marks) and K (number of re-evaluations only) f(K,M). And now observe, a child would go for re-evaluation only if he scores less than or equal to f(K-1,M) else he won't go for further re-evaluations.

Author Solution

### Divide the Country

Problem Author: se7enth_hea7en

For this problem in particular we saw a lot of creative solutions. But still for the sake of editorials, here is the solution we thought.

First, check if the given graph is a tree. If yes, then output n — 1. If not then there exists at least one cycle. Choose any vertex which is part of a cycle. Let's call it u. Run dfs from u. Now suppose you are currently at vertex v. If there is a non-bridge vertex in the dfs subtree of v then you obviously cannot remove the edge between v and its parent and it is no longer a candidate for the answer. After checking that condition if the edge between v and parent of v is still a candidate then it means that the dfs subtree of v consists only of bridges. Keep track of the diameter of the subtree. If diameter is same as the current maximum diameter then check for the number of nodes in the subtrees.

Author Solution

### Will You Win The Prize?

Problem Author: Gauri_Jain

The question is given as if it has to be solved online, but actually it is an offline question. Take all the characters given in all queries in sequence to make a string (S1). The given string is named as (S). Make string (T)=S1+#+S. Now apply “KMP” on this string (T). In the array obtained by KMP take the answer from (n+1)th index to (2n)th index. This is our required l(i). So, ans(i)=l(i)*2^i. It’s easy to calculate the binary representation of ∑(i=1 to i=n) ans(i). Refer to the solution code for better understanding.

Author Solution

### Yet Another Permutation Array!

Problem Author: samraj2k

With the given cumulative sum array A, find out the elements in the array P. This can be easily done by knowing how cumulative array get build. The first element of the cumulative array will also be present the array P. The rest elements can be found using A[i]-A[i-1] for all i>=1 to n-1 (0-based indexing). Now in these conditions answer will be -1: 1. The number of distinct elements in P are not n. 2. If the distinct elements are n, all integers from 1 to n are not present. This can be done by storing the above made P array elements in set data structure and iterating them. In all other cases answer exists. Print the array P formed.

Author Solution

### Binary Matching

Problem Author: Nightmare05

Since a lot of people were interested in the proof of this problem specially, I decided to write a complete rigorous proof and well since some stuff is mathematical I am writing on paper and uploading pics. Pic 1 Pic 2

Author Solution Comments (13)
 » Auto comment: topic has been updated by Nightmare05 (previous revision, new revision, compare).
 » Auto comment: topic has been updated by Nightmare05 (previous revision, new revision, compare).
 » can you give a brief outline for "Universe is random problem", how you got that formula , also the problem statement is not so clear with no explanation for sample test case.i understood that N is irrelavant but why is E ignored in solution what happens if E
•  » » Bro the problem was trying to say that each student has to give E exams irrespective of anything, going for re evaluation means just re-grading an already given exam, in re-evaluation you do not appear again for an exam, so E and K are independent of each other and the expected marks in 1 exam would be same as average expected marks over E exams irrespective of E, hence the answer is independent of E.
•  » » See bro as of the line f(K-1,M), after a student gave an exam, and it got graded, since he is mathematically sound enough, you had to observe that he will be willing to go for re-evaluation only if his score is less than f(K-1,M). f(K-1,M) is the answer if only (K-1) re-evaluations were allowed. Else he would just keep his marks. In simpler words assume that M=100 and K=1, so a student who got more than 50 marks directly, won't go for re-evaluation, rest would go for re-evaluation.
 » Can you please make the test cases for the problems public? I wasn't able to figure out the mistake in my code for the problem Will You Win The Prize?. So, I would like to see the test case to see where was I going wrong.
•  » » See bro, I'm not sure if we can make them public but if u really want them just gimme ur hackerearth handle, I'll give the test cases where you were failing
•  » » » Thanks. My hackerearth handle is roll_no_1.
•  » » » » 12 months ago, # ^ | ← Rev. 2 →   Try this test case your last submission fails on this.8abcdababbcdaabbd
•  » » » » » 12 months ago, # ^ | ← Rev. 2 →   Thanks a lot. Got my mistake. :)
•  » » » » » » Cool
 » https://ibb.co/s3VmPZf Can you check this box?
•  » » Done problems have been moved to practice section.