Hi guys,↵
↵
I would like to thank all participants for making this event a grand success and specially thank [user:Journey_Begin,2019-11-16], [user:darklight13,2019-11-16], [user:se7enth_hea7en,2019-11-16], [user:kunj017,2019-11-16], [user:samraj2k,2019-11-16], [user:Gauri_Jain,2019-11-16] and [user:hackcyborg,2019-11-16] 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:↵
↵
1. [user:nuip,2019-11-16]↵
↵
2. [user:amoo_safar,2019-11-16]↵
↵
3. [user:pshishod2645,2019-11-16]↵
↵
4. [user:kimden,2019-11-16]↵
↵
5. [user:scopeInfinity,2019-11-16]↵
↵
Based on the leaderboards following people have qualified for prizes:↵
↵
Overall top 3:↵
↵
1. [user:nuip,2019-11-16]↵
↵
2. [user:amoo_safar,2019-11-16]↵
↵
3. [user:pshishod2645,2019-11-16]↵
↵
Top 5 Indians:↵
↵
1. [user:pshishod2645,2019-11-16]↵
↵
2. [user:scopeInfinity,2019-11-16]↵
↵
3. [user:cerberus97,2019-11-16]↵
↵
4. [user:_shanky,2019-11-16]↵
↵
5. [user:hitman623,2019-11-16]↵
↵
Top 2 from IIT Patna(presently studying):↵
↵
1. [user:intruder_p,2019-11-16]↵
↵
2. [user:DeepThought42,2019-11-16]↵
↵
Winner from 1st year IIT Patna↵
↵
1. [user:harsh__2001,2019-11-16]↵
↵
↵
**Editorals!**↵
------------------↵
↵
↵
### [**_Is It Some Space Cakewalk?_**](https://www.hackerearth.com/challenges/college/byterace2k19/algorithm/7fc567cab826402297ac29bab91918df/)↵
↵
**Problem Author:** [user:darklight13,2019-11-16]↵
↵
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`](https://paste.ubuntu.com/p/bxZKNNj7n4/)↵
↵
↵
### [**_Kunj Destroys Asteroids in 13th Dimension_**]↵
(https://www.hackerearth.com/challenges/college/byterace2k19/algorithm/ce46562365d64992ae2864bbc2172dde/)↵
↵
**Problem Author:** [user:darklight13,2019-11-16]↵
↵
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 the answer.↵
↵
[`Author Solution`](https://paste.ubuntu.com/p/x79jk9KChh/)↵
↵
↵
### [**_1-2-3 Subsequence_**]↵
(https://www.hackerearth.com/challenges/college/byterace2k19/algorithm/6955a2c45dfa493eb131e91c33f838b8/)↵
↵
**Problem Author:** [user:samraj2k,2019-11-16]↵
↵
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://mirror.codeforces.com/blog/entry/71357?#comment-558146↵
Thanks to [user:pshishod2645,2019-11-16]↵
↵
[`Author Solution`](https://paste.ubuntu.com/p/NvqZ8CSgxx/)↵
↵
↵
### [**_Universe is random, but is it?_**]↵
(https://www.hackerearth.com/challenges/college/byterace2k19/algorithm/5222a4cd24da430a98208076a8622e24/)↵
↵
**Problem Author:** [user:Nightmare05,2019-11-16]↵
↵
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`](https://pastebin.com/gdXq2sBe)↵
↵
↵
### [**_Divide the Country_**]↵
(https://www.hackerearth.com/challenges/college/byterace2k19/algorithm/a4a5a249a2e345d89966881cd07d46b7/)↵
↵
**Problem Author:** [user:se7enth_hea7en,2019-11-16]↵
↵
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`](https://pastebin.com/F6byk8Cr)↵
↵
↵
### [**_Will You Win The Prize?_**]↵
(https://www.hackerearth.com/challenges/college/byterace2k19/algorithm/1b166c3895854952a806012b3eb0181e/)↵
↵
**Problem Author:** [user:Gauri_Jain,2019-11-16]↵
↵
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`](https://paste.ubuntu.com/p/nGkXgWGFC5/)↵
↵
↵
### [**_Yet Another Permutation Array!_**]↵
(https://www.hackerearth.com/challenges/college/byterace2k19/algorithm/ca67412e5f1043c495f3abf3ca239a42/)↵
↵
**Problem Author:** [user:samraj2k,2019-11-16]↵
↵
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`](https://paste.ubuntu.com/p/2HjF3Wdnpw/)↵
↵
↵
### [**_Binary Matching_**]↵
(https://www.hackerearth.com/challenges/college/byterace2k19/algorithm/8108cd326e474adda6401beadbaf60b6/)↵
↵
**Problem Author:** [user:Nightmare05,2019-11-16]↵
↵
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](/predownloaded/7b/0a/7b0a2258bb170b2d1dc214acb0f0e942aae0f2f4.jpg)↵
[Pic 2](/predownloaded/b9/88/b988ee22056c56027be68bedec253d77c1ee3f4a.jpg)↵
↵
[`Author Solution`](https://pastebin.com/f36iEs45)
↵
I would like to thank all participants for making this event a grand success and specially thank [user:Journey_Begin,2019-11-16], [user:darklight13,2019-11-16], [user:se7enth_hea7en,2019-11-16], [user:kunj017,2019-11-16], [user:samraj2k,2019-11-16], [user:Gauri_Jain,2019-11-16] and [user:hackcyborg,2019-11-16] 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:↵
↵
1. [user:nuip,2019-11-16]↵
↵
2. [user:amoo_safar,2019-11-16]↵
↵
3. [user:pshishod2645,2019-11-16]↵
↵
4. [user:kimden,2019-11-16]↵
↵
5. [user:scopeInfinity,2019-11-16]↵
↵
Based on the leaderboards following people have qualified for prizes:↵
↵
Overall top 3:↵
↵
1. [user:nuip,2019-11-16]↵
↵
2. [user:amoo_safar,2019-11-16]↵
↵
3. [user:pshishod2645,2019-11-16]↵
↵
Top 5 Indians:↵
↵
1. [user:pshishod2645,2019-11-16]↵
↵
2. [user:scopeInfinity,2019-11-16]↵
↵
3. [user:cerberus97,2019-11-16]↵
↵
4. [user:_shanky,2019-11-16]↵
↵
5. [user:hitman623,2019-11-16]↵
↵
Top 2 from IIT Patna(presently studying):↵
↵
1. [user:intruder_p,2019-11-16]↵
↵
2. [user:DeepThought42,2019-11-16]↵
↵
Winner from 1st year IIT Patna↵
↵
1. [user:harsh__2001,2019-11-16]↵
↵
↵
**Editorals!**↵
------------------↵
↵
↵
### [**_Is It Some Space Cakewalk?_**](https://www.hackerearth.com/challenges/college/byterace2k19/algorithm/7fc567cab826402297ac29bab91918df/)↵
↵
**Problem Author:** [user:darklight13,2019-11-16]↵
↵
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`](https://paste.ubuntu.com/p/bxZKNNj7n4/)↵
↵
↵
### [**_Kunj Destroys Asteroids in 13th Dimension_**]↵
(https://www.hackerearth.com/challenges/college/byterace2k19/algorithm/ce46562365d64992ae2864bbc2172dde/)↵
↵
**Problem Author:** [user:darklight13,2019-11-16]↵
↵
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 the answer.↵
↵
[`Author Solution`](https://paste.ubuntu.com/p/x79jk9KChh/)↵
↵
↵
### [**_1-2-3 Subsequence_**]↵
(https://www.hackerearth.com/challenges/college/byterace2k19/algorithm/6955a2c45dfa493eb131e91c33f838b8/)↵
↵
**Problem Author:** [user:samraj2k,2019-11-16]↵
↵
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://mirror.codeforces.com/blog/entry/71357?#comment-558146↵
Thanks to [user:pshishod2645,2019-11-16]↵
↵
[`Author Solution`](https://paste.ubuntu.com/p/NvqZ8CSgxx/)↵
↵
↵
### [**_Universe is random, but is it?_**]↵
(https://www.hackerearth.com/challenges/college/byterace2k19/algorithm/5222a4cd24da430a98208076a8622e24/)↵
↵
**Problem Author:** [user:Nightmare05,2019-11-16]↵
↵
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`](https://pastebin.com/gdXq2sBe)↵
↵
↵
### [**_Divide the Country_**]↵
(https://www.hackerearth.com/challenges/college/byterace2k19/algorithm/a4a5a249a2e345d89966881cd07d46b7/)↵
↵
**Problem Author:** [user:se7enth_hea7en,2019-11-16]↵
↵
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`](https://pastebin.com/F6byk8Cr)↵
↵
↵
### [**_Will You Win The Prize?_**]↵
(https://www.hackerearth.com/challenges/college/byterace2k19/algorithm/1b166c3895854952a806012b3eb0181e/)↵
↵
**Problem Author:** [user:Gauri_Jain,2019-11-16]↵
↵
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`](https://paste.ubuntu.com/p/nGkXgWGFC5/)↵
↵
↵
### [**_Yet Another Permutation Array!_**]↵
(https://www.hackerearth.com/challenges/college/byterace2k19/algorithm/ca67412e5f1043c495f3abf3ca239a42/)↵
↵
**Problem Author:** [user:samraj2k,2019-11-16]↵
↵
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`](https://paste.ubuntu.com/p/2HjF3Wdnpw/)↵
↵
↵
### [**_Binary Matching_**]↵
(https://www.hackerearth.com/challenges/college/byterace2k19/algorithm/8108cd326e474adda6401beadbaf60b6/)↵
↵
**Problem Author:** [user:Nightmare05,2019-11-16]↵
↵
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](/predownloaded/7b/0a/7b0a2258bb170b2d1dc214acb0f0e942aae0f2f4.jpg)↵
[Pic 2](/predownloaded/b9/88/b988ee22056c56027be68bedec253d77c1ee3f4a.jpg)↵
↵
[`Author Solution`](https://pastebin.com/f36iEs45)