Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all 39796 articles
Browse latest View live

Unofficial Editorials November Long Challenge (Part 1)

$
0
0

Hello Guys

I have divided problems into posts according to difficulty. Hope u all don't mind this. ;)

This is the part 1 of two posts of unofficial editorials for November Long Challenge.

For editorials of problems CSUBQ and SEGPROD, click here.

This post has editorials for problems VILTRIBE, CLRL, PERPALIN and CHEFHPAL (so many in single post :) ).

Problem VILTRIBE

Problem Difficulty : Cakewalk

Problem Explanation

Given a string consisting of characters 'A', 'B' and '.', Output number of characters controlled by A and B. Character C controls ith character if either of following condition is true.

  1. Ith character is C
  2. Ith character is '.' and the character on both side is C (jumping all the '.' characters in between)

Solution

Just do as they asked in the problem. :)

Maintain a character C (initialised to any other character of your choice other than 'A', 'B' and '.') which denote the previous controlling character encountered.

Here, we are going to count characters satisfying above of the two conditions separately Beacuse if we choose to count them together, there's a risk of counting characters satisfying first condition twice, which is certainly not what we want.

For example of this, try input A.A.A...B.B.B

Maintain counter variables countA, countB, A, B and last where

  1. countA means number of '.' characters being controlled by 'A'
  2. countB means number of '.' characters being controlled by 'B'
  3. A means No of 'A' in input
  4. B means No of 'B' in input
  5. last means index of last controlling character. (Initialised to -1)

After all this, I guess my solution is straight forward to understand. In case you feel i should clarify any doubt, Just drop a comment. :)

Here's a link to my Code

Problem CLRL

Problem difficulty:Simple

Problem Explanation

Given an array of numbers, we are supposed to verify whether the array is valid based on given condition.

Solution

The most simple way to think about this as following:

Here, Ri denote ith element of given array.

The given array is valid if and only if:

For every pair of consecutive numbers R(i-1) and Ri:

If R(i-1) < Ri : R(i-1) < all elements after ith index. (type 1)

If R(i-1) > Ri : R(i-1) > all elements after ith index. (type 2)

That's it. we just need to implement it.

I have used two boolean to check if any pair of type 1 and type 2 is found.

Basic case : N <= 2 Answer is "YES" No matter what the elements are. (Be sure to input them or you'll get WA) For explanation, i set reward if anyone finds such a case with N <= 2 where answer is NO, He or she'll be appreciated in my next post. Good Luck :)

Use max and min variable to keep record of upper and lower bound.

loop from start+1 to end

compare elements (i-1) and ith position.

if (i-1)th < ith

if(type1 is not found yet) found1 = true. min = ith element

if type 2 is found && ith element > max, valid = false

min = Math.min(min, prev)

Other case works the same way. Just swap type 2 with type 2, min and max and invert the inequalities. if valid print "YES" else "NO"

Link to my code

Problem PERPALIN

Problem Difficulty : Simple

Problem Explanation

Given two integers N and P, construct a palindrome string of length N in which every ith character is same as (i+P)th character using only characters 'a' and 'b'. If not possible, print impossible.

Further, String should not contain all a or all b.

Solution

First thing to observe is that in case P == 1 OR P == 2, ans is impossible.

Reason

if P == 1, valid strings are only aaaaa... (upto N times) or bbbbb... (upto N) times. But as Chef dislikes these strings, ans is impossible.

if P == 2, the only valid strings can be abababab or babababa. Since N is always divisible by P, N is not odd in this case, and when N is Even, first and last character of string is never same. So we cannot get a palindrome of period length 2. ans is impossible.

In all other cases, Answer always exist.

Here, there exists many solutions for this problem. But I'm gonna tell which approach i used.

Small string of length P will be repeated N/P times to generate the required string of length N.

I generated small string as:

In case P is odd, just make string ababababa till length P

If P is even: (P+2)/4 times 'a' + (P/4)*2 times 'b' + (P+2)/4 times 'a' (Integer division)

You may ask why i chose such a complex way to generate this string for even P. The reason is, My Choice. :D

It always make palindrome string for even length >= 4.

First few strings for even P would be abba, aabbaa, aabbbbaa, aaabbbbaaa

Just see first half of strings => ab, aab, aabb, aaabb. My pattern make strings like that, increasing a and b one by one and then reverse it and append it to original one.

Hope i didn't confused you with my small rant. Feel free to ask.

Here's a link to my Code

Problem CHEFHPAL

Problem Difficulty : Easy

Problem Explanation

Given two integers N and A, construct a string of length N using only first A characters, minimizing length of longest palindrome substring. 2<=A<=26

Solution

First thing to observe here is that for A > 2, One of the correct answer is "1 abcabcabc..." upto N characters because this string cannot have any palindrome of length greater than one.

So that just leaves A == 2, The Special Case

Here, I am making a statement, Do tell me any counter example and you will be appreciated.

For N > 8, there is always a string whose maximum palindrome sub-string length is exactly 4.

I have tested many strings using a tester program, generating strings using two characters 'a' and 'b', and found this. An alternative solution is most welcome. (If you want the tester program i used, I'd recommend you to make it yourself, it would boast your skills. :) )

The reason that this works is that for a palindrome of length >= 4, we need two pair of character matching (first with last, second with second last), so we are creating a single mismatch every time.

We can't avoid palindrome length 4 after N >= 8 because consider a string aaababbb, now if we append 'a', palindrome length is 5, if you append 'b', palindrome length becomes 4.

See string babbaababbaa. This string always create exactly one mismatch for substring of length > 4. (You can always find such a string with hit and trial).

So, I simply stored results for N <= 8 in an array.

So, i just check A>2, if yes, print abcabcabc... upto n characters.

else if N <= 8, print answer pre-calculated (Or calculate using program if you can)

else append above string repeatedly to output string till output length is exactly N. Remove extra characters in case length > N.

Here's a link to my Code.

As always, i wholeheartedly invite your suggestions and thank for your response to my previous editorials.


Editorial of POLY not posted yet.

$
0
0

It's been 5 days since the end of November Long challenge. But still, editorial of problem POLY has not been updated yet. I wish to bring this fact to the knowledge of @admin. Hope the editorial will be posted soon.

Unofficial Editorials November Long Challenge (Part 2)

$
0
0

Hello Guys

I have divided problems into posts according to difficulty. Hope u all don't mind this. ;)

This is the part 2 of two posts of unofficial editorials for November Long Challenge.

For editorials of problems VILTRIBE, CLRL, PERPALIN and CHEFHPAL, click here.

This post has editorials for problems SEGPROD and CSUBQ.

Problem SEGPROD

Problem Difficulty : Medium

Prerequisites:Modular Multiplicative Inverse (euclid's method), Simple maths, and patience.

Problem Explanation

Given an array and a number P (not necessarily prime), Answer range product queries modulo P. (Not as simple as it looks).

Solution

The first thing i want you all understood is the euclid method of finding modular multiplicative inverse, vital to my approach, about which you may read from wikipedia and find the algorithm here.

The naive brute force (not at all successful even for 20 points, due to integer overflow) would be to create a prefix product array (similar to prefix sum array) and for every query L to R, output prefixProd(R) / prefixProd(L-1) and output modulo P. That's correct, but incapable of giving us 100 points.

So, we move to modular multiplicative inverse (MMI) for help!!. We will to the same thing. Instead of prefix product, we will make an array storing prefix modular product (mod P ofcourse). Now, to answer queries, we are going to answer queries just as prefixModProduct(R)/prefixModProduct(L-1).

This is same as (prefoxModProduct(R) * ModInverse(L-1))%P.

If you have followed the logic upto here and understood MMI from geeksforgeeks page, you have earned 20 points. Hurray.

The reason of only 20 points is that Modular multiplicative inverse of a number A exists only when A and P are co-prime (gcd(A,P)==1). For first subtask, it was given that P is prime and all numbers are smaller than P. From that, it's obvious that gcd(A, P) is one for every element, so we get 20 points.

Now, for full solution, we will use the same technique, but with a slight change in plan. Now, we will first find prime factors of P (U'll understand why) and handle numbers in a different way, which will be explained by an example.

Suppose P = 6 and given array is 1 2 3 4 5 6 7 8 9 10

Now, Prime factors of 6 are 2 and 3.

Now, we will handle powers of 2,3 separately and rest numbers separately.

Create an array factors which will have value {2,3} for this example. create a 2d array factorPowSum[NumberOfFactors][N]

factorPowSum array will look like below (explained how to make this below that)

factor 0 1 2 3 4 5 6 7 8 9 10 11

2..... 0 0 1 1 3 3 4 4 7 7 8 8 (dots to adjust position, spaces are truncated automatically)

3..... 0 0 0 1 1 1 2 2 2 4 4 4

And we will think(it's necessary) we are given given array 1 1 1 1 5 1 7 1 1 5 11 (all numbers are divided by 2 and 3). Now, you will see that all numbers are co-prime to 6. Now we can use the algorithm to solve the queries for reduced array.

Let's assign factor 2 to index 0 and factor 3 to index 1.

Creation of factPowSum array

Just assign factPowSum{factorIndex}{0} = 0 and for 0<i<=N

factPowSum{factorIndex}{i} = factPowSum{factorIndex}{i-1} + Power of factor divided from ith number(1-based indexing).

For example, from 8, 3rd pow of 2 was divided, factorPowSum{0}{3} = factorPowSum{0}{4} + 3.

Hope i made the array clear.

Now, consider that we are given only powers of factors of P.

Continuing same example, The same array we were working with now becomes (I know this is lengthy as hell, but I tried making it as easy to understand as possible)

1 2 3 4 1 6 1 8 9 2 1 (Only powers of 2 and 3 are considered from given array).

Now, if someone ask us range query on this array, we can answer each query within O(number of factors of P) time.

This is simple, just refer to factPowSum array and give it a try. Read further only after a try.

let ans = 1.

for every factor of P, ans = ans*pow(factor, factPowSum{R+1}-factPowSum{L}).

Now, combining above two sub-problems, we get answer of query as

let ans = (prefixModProd(R+1)*MMI(L) * product(pow(factor, factPowSum[R+1]-factPowSum[L])) )%P.

// The queries in question are 0-indexed

You are about to lose 100 points if you do this. Shocked!!. Be sure to take modulo after every multiplication so as to lose your AC to Integer overflow, use long long int/long only.

Now you all deserve 100 points in this problem, but you will get TLE because test cases were too tight. Calculating powers with fast modulo exp even takes O(logN) time, which is too much for 10^7 queries. So we calculate powers of factors of P before answering queries and store in an array. I am not going to explain this but it's easily understandable from my code. In case you need help, feel free to ask.

Added Proof:

lemma: P can have at most 10 different prime factors.

Proof: Try multiplying first eleven prime numbers. The product will be greater than 10^9. but as P <= 10^9, it follows that maximum number of distinct prime factors P can have is 10.

Here's a link to my Code. (Took nearly 30 submissions for 100 points :D)

Problem CSUBQ

Problem difficulty:Medium

Prerequisites:Segment Tree, Too much patience unless u r a segment tree expert (msg me if u are, want a talk.)

Problem Explanation

An array of Size N and M queries, Tow Integers L and R (L<=R), handle following queries. 1. update ith value to X. 2. Find number of subarrays betweeen L and R, whose maximum values lie between L and R. (both inclusive)

Solution

One basic formula. (very basic)

let function c denote c*(c+1)/2 (The number of all the possible contigious subarrays from an array of length c.)

1+2+3+4+5 ... (N-1) + N = N(N+1)/2

Now, take L = 1, R = 10 and given array 2 0 11 3 0 (example given in problem)

(I'm directly taking an array instead of a series of updates to explain it).

Required subarrays between 1 to 5 are {1, 1}, {1,2},{4,4} and {4,5}

An interesting thing to observe is that ans = c(2)-c(1)+c(2)-c(1) (I'll explain how i came up with this.)

Two Facts: 1. Any element > R is never included in any subarray (like element 3). 2. Any number of elements smaller than L can be included in subarray as long as there is atleast one single element between L and R inclusive.

So, we are going to get 25 points first using this fact.

See this solution for details. in this solution, inc means consecutive elements till now which are smaller or equal to R, and exc means all consecutive elements < L till current position. Whenever we reach an element >= L, subtract excluded subarray count ( c(exc) ) from count and set exc = 0 and inc++ and whenever u get an element > R, add c(inc), subtract c(exc) and set both to 0. otherwise inc++, exc++.

Ans is count + c(inc)-c(exc). Got 25 points. This solution runs in O(QN) time.

I hope this logic is clear. Because if it isn't, be sure to read again once, twice, 10 times, 10^2 times, 2^ 10 times (I like this quote :P).

Now, Getting 52 points isn't difficult if You have heard about square root decomposition. I have submitted a solution using this technique too. :P. (I submitted too many solutions for this) I used in this solution apart from the counting technique we discussed above and one thing mentioned below

Cheers, now we got 52 points with this ease, but no longer. Problem setters aren't going to gift 52 points with this ease.

Now, think here, what information about a segment L to I and a segment from I+1 to R we need to find out all required information.

Refer to my solution (One more solution :P) alongwith to understand what's going on.

Let me help u. You need 8 variables (too much u feel i guess), as follows: 1. count => The count of subarrays already included in range, except those at borders. 2. incL => Number of elements from left to leftmost element which is > R. (0 if there's no element > R in range) 3. incR => Number of elements from right to rightmost element which is > R. (0 if there's no element > R in range) 4. excL => Number of elements from left to leftmost element which is >= L. (0 if there's no element >= L in range) 5. excR => Number of elements from right to rightmost element which is >= L. (0 if there's no element >= L in range) 6. size => size of range 7. found1 => boolean, which tells whether range contains atleast one element > R. 8. found2 => boolean, which tells whether range contains atleast one element >= L.

Any ideas how we are going to merge ranges?, it's simple enough.

Consider array 2 0 1 11 3 0 5

Answer of this Problems is c(3)-c(1)+c(3)-c(1) = 6-1+6-1 = 10

Think of this problem in two parts. for elements > R and for elements >= L.

For first part, consider any element > R as dividing element. for above example, 11 is dividing the total ranges into two sub-ranges of length 3 each.

For second part, consider any element >= L as dividing element. For above example, 2,1,11,3 and 5 are dividing elements, resulting in 2 ranges of length 1. ( {1,1} and {5,5} ).

If you understood this part, You can divide the given problem into two parts, the one dealing with elements to be included, and the one dealing with elements to be excluded.

Here comes the Main part of solution,The Segment tree. Now, as you may see, i have used an iterative segment tree,(I messed up recursive one and also, iterative is slightly faster if u take the trouble to understand it) about which you may read here. I first of all, created a class S (struct equivalent in java) which hold all this info about each segment of tree.

Now, the most important thing is to create a merge function, which will merge two segments into a larger one correctly.

You may see from my code, i have dealt with inclusion and exclusion separately, making my code simpler.

For first part, i check if both sides have element > R (our dividing element) (using boolean found1). if both has, include Left of large range will be outL of left segment and include right will be includeRight of right segment. count will be increase by c(left.incR + right.incL) because they are no longer boundary elements of segment.

In case only one segment has dividing element, incL and incR of output range is assigned accordingly.

Same way for large. And Here we go. We have solved the problem. Bet you didn't realize that.

All that is left to implement it. And Now, nothing is going to stop you from 100 points except a TLE in one file. (Not Sure, because i had use the following tip to save time.)

Link to My code.

PS: This was my first editorial using segment trees. So, i am sorry if any error might have crept in (without my knowledge, of course) Do give your review for this editorial.

As always, i wholeheartedly invite your suggestions and thank for your response to my previous editorials.

PS:Sorry for delay, was held up in something important. Delay gift will be posted as soon as I learn the technique of problem Polynomial. :D Hope you don't mind delay in delay gift. :D

ZIO 2018 answers and cutoff discussion

$
0
0

Please share your answers for ZIO here... And tell what cutoff you expect I personally found it easy..(similar to last year) and expect the cutoff to be around 50-55 Until now, these are the answers I can almost confirm,

  1. 74
  2. 67
  3. 65
  4. 3
  5. 2
  6. 4
  7. 20
  8. 16
  9. 96
  10. 49/61
  11. 261/321

Laddus for November Long Challenge

$
0
0

Has the laddus for NOV17 delivered or Chef is busy with other stuffs?

POLY - Editorial

$
0
0

PROBLEM LINK:

Practice
Contest

Author:Trung Nguyen
Tester:Istvan Nagy
Editorialist:Oleksandr Kulkov

DIFFICULTY:

HARD

PREREQUISITES:

Li Chao segment tree OR good sense of lower hull trick

PROBLEM:

You have $n$ polynomials $y_i(x)=a_0+a_1x+a_2x^2+a_3x^3$ and $q$ queries in which you are asked to find $y_i$ which minimizes $y_i(t)$.

QUICK EXPLANATION:

Solve problem via brute force for small $t$ and for large use Li Chao segment tree.

EXPLANATION:

Consider polynomial $y_i-y_j$ for some $i$ and $j$. Its degree is at most three.

Lemma: Polynomial $y=x^3+ax^2+bx+c$ has at most one root greater than $k=\sqrt{\max(|b|,|c|)}+2$.

Proof: Let $u\geq v >k\geq w$ to be the roots of $y$. Then $y=(x-u)(x-v)(x-w)$ so $b=uv+uw+vw$, $c=-uvw$. Since $u,v>\sqrt {|c|}$ it holds that $|w|<1$. Thus $b=uv+w(u+v)> uv-(u+v)=(u-1)(v-1)-1$. But since $u,v>\sqrt {|b|} + 2$ we have $b> (\sqrt {|b|} + 1)^2-1=|b|+2\sqrt {|b|}>b$ which is contradiction. $$\tag*{$\Box$}$$

Given this and the fact that for $x^2+bx+c$ at most one root greater than $\sqrt{|c|}$ (due to their product being equal to $c$) we can just manually check first $350>\sqrt{10^5}$ integer points and consider functions only on set of points after $350$ when any two functions will have at most one intersection points due to their difference being at most third degree polynomial.

Now to handle queries on $[350,+\infty)$ we will use Li Chao segment tree. Assume you're given set of functions such that each two can intersect at most once. Let's keep in each vertex of segment tree some function in such way that if we go from root to the leaf, it will be guaranteed that among functions we meet on the path will be the one giving minimum value in that leaf. Let's see how to construct it.

Assume we're in some vertex corresponding to half-segment $[l;r)$ and function $f_{old}$ is kept there and we adding to the set function $f_{new}$. Then intersection point will be either in $[l;m)$ or in $[m;r)$ where $m=\left\lfloor\dfrac{l+r}{2}\right\rfloor$. We can efficiently learn that comparing values of functions in points $l$ and $m$. If dominating function changes then it's in $[l;m)$ otherwise it's in $[m;r)$. Now for the half of segment where there no intersection we pick lower function and write it in current vertex. After that we recursively go to the other half of segment with the function which was upper one. As you can see this will keep correctness on the first half of segment and in the other one correctness will be maintained during the recursive call. Thus we can add functions and check the minimum value in the point in $O(\log C)$.

Here is the illustration of what's going on in the vertex when we consider adding in it new function:

alt text

In this particular case we will keep new in the vertex and recursively call in the left segment with old function.

ALTERNATIVE SOLUTION

One can construct hull of functions in offline instead of using LiChao tree. If function $f_a$ less than function $f_b$ on $x\to+\infty$ and they have at most one point of intersection then $f_a$ coefficients $(a_3,a_2,a_1,a_0)$ lexicographically smaller than coefficients of $f_b$. Thus we can firstly sort functions in descending order of their coefficients and then add functions one by one to maintain the lower envelope.

We will keep them in stack. Assume this stack to be $(f_1,f_2,\dots,f_k)$ and points $350< x_2< \dots< x_k$ are the intersections of the functions. Then function $f_i$ have least value among all functions on $(x_i,x_{i+1})$ with $x_1=350,x_{k+1}=+\infty$. If we consider new function $f_{k+1}$ with all coefficients lexicographically smaller than ones of functions we have then there will be such point $x_0$ that it will have smaller values than all functions on $(x_0,+\infty)$ and it will still have larger values than functions from envelope on $(350,x_0)$. So we can repeatedly remove functions $f_k$ till they have larger values than both $f_{k+1}$ and $f_{k-1}$ at the point where functions $f_{k-1}$ and $f_{k+1}$ intersect and add function $f_{k+1}$ in the stack afterwards. This will be sufficient to build lower envelope of functions and if you also keep their intersection points then you can use binary search to find function with lowest value in given point $x$.

This approach strongly generalizes well-known convex hull trick for the case in which we have set of non-necessarily convex functions with the property that they have at most one intersection and we can calculate beforehand which order will they have if we consider them for $x\to+\infty$.

Finally, to illustrate the solution, I'll provide some pictures. Assume you had functions $f_1$, $f_2$, $f_3$ in the stack.alt text

And now you want to add $f_4$.alt text

As we see function $f_3$ is no use at all since it is above point of intersection of functions $f_2$ and $f_4$. So we remove it and place $f_4$ in its place in the stack.

alt text

AUTHOR'S AND TESTER'S SOLUTIONS:

Author's solution can be found here.
Tester's solution can be found here.

RELATED PROBLEMS:

How should I test my program

$
0
0

I am done writing the code. And I am not sure if my program works correctly or not. How do I go about testing it?

Confirmation Mail

$
0
0

Can anyone tell me how long after release of selected team names the corresponding teams receive confirmation email?


Contest Timing for 20 NOV

$
0
0

Tomorrow there are two contests at same time.I think no two contests should be given same timings

Can it be changed?

Teams Selected for Amritapuri and Kanpur

$
0
0

How do you plan to travel between Kanpur (24th Dec) and Amritapuri(26th Dec) ?

ICPC Kolkata/Kanpur region

$
0
0

We got selected for the Kolkata Kanpur onsite. How and when will we know which city we need to report to? We have to book train tickets accordingly.

Codechef Rating Predictor

$
0
0

Hello everyone!

alt text

Codechef Rating Predictor

The delay in previous month rating changes + inspiration from CF Predictor and for the practice of a web-application, i tried to write a script that can predict rating changes from ongoing live contests @ Codechef.

While the actual delays in rating changes s/would be fixed, this script can help in predicting rating changes as new submissions are made, so hopefully it can be useful for Long contests :).

The script is written in nodejs and is based on open rating formulas available at this link. The code for the project can be accessed here

Website is currently hosted on Openshift free servers and has few restrictions on use. Therefore the server might be slow or not responding during the period rating changes are calculated. Currently, ratings are expected to be updated every 15 minutes

I also tested rating changes on few past contests and the predictions were accurate within an error of 2 for almost everyone except the first rank (I have no idea why first rank predictions are wrong in some contests using current formulas)

Please note that project is still in beta stage and also actual changes might differ more due to changes in ranklist after plagiarism detection

Your feedback/suggestions would be appreciated

JUNE17 Links:

All: http://codechef-rating-predictor.7e14.starter-us-west-2.openshiftapps.com/contest/JUNE17/all/

Long: http://codechef-rating-predictor.7e14.starter-us-west-2.openshiftapps.com/contest/JUNE17/long/

Few stats on JUNE17 Predictions. I matched ratings (All) of first 6391 users and the results were as follows:

Difference - No of users

  • 0 - 5868
  • 1 - 275
  • 2 - 125
  • 3 - 68
  • >= 4 - 55

There were around 40 users having difference > 50. Turns out some usernames appears to be missing in the ranklist when sorted by rank and hence they were showing as last in the prediction list.

I ran the code again after fixing the above bug and results are better now (Maximum difference is 8)

  • 0 - 5900
  • 1 - 485
  • >= 2 - 6

COOK83 Links:

All: http://codechef-rating-predictor.7e14.starter-us-west-2.openshiftapps.com/contest/COOK83/all/

Short: http://codechef-rating-predictor.7e14.starter-us-west-2.openshiftapps.com/contest/COOK83/short/

The ratings are expected to update every 5 minute

Few stats, 4811/4820 predictions (for both all and cook-off predictions) were right. Rest have diff < 3 with the exception of rating prediction of first rank in cook off. Also, as @vikasj554 pointed out, few users got rating changed after initial update. (I still need to figure out why this happened). But even after this 4794/4820 predictions were accurate.

LTIME49 Links:

All: http://codechef-rating-predictor.7e14.starter-us-west-2.openshiftapps.com/contest/LTIME49/all/

Lunchtime : http://codechef-rating-predictor.7e14.starter-us-west-2.openshiftapps.com/contest/LTIME49/ltime/

The ratings are again expected to update every 5 minute

JULY17 Links:

All: http://codechef-rating-predictor.7e14.starter-us-west-2.openshiftapps.com/contest/JULY17/all/

Long : http://codechef-rating-predictor.7e14.starter-us-west-2.openshiftapps.com/contest/JULY17/long/

Update frequency: 10 mins

ICPC 2017 Results - But Why?

$
0
0

Hello Codechef Community,

I had earlier recorded my thoughts about the online round, and the subsequent calls for a "recontest" , here (LINK)

With some of the regional sites releasing the results today, I just thought I'd record my conception of the same here.

Amritapuri has 250 slots, and almost 230-240 unique colleges have been invited. This is ABSURD! Yes, the spirit of ICPC is to spread the idea of programming far and wide, but is this move going to backfire in the long run? There are teams who have secured a rank > 2000 in the list and qualified, but teams that came within 100 ranks in the original rank list, lose out simply because they couldn't attain the "college first" rank.

I, for one, gave Competitive Programming my everything for the past one year, in the hope of performing well in ICPC. There are many many others who do the same, but ultimately lose out on this because of this dubious selection criteria.

What happens if they give up on competitive programming because of this? I know there's an argument that one shouldn't materialistically do CP for the purpose of results in contests, but come on! Losing a coveted spot at the regionals because of no fault of theirs, seems to be extremely hard to digest.

Maybe having a certain slot (50-60% of the seats) reserved for the college-first teams, and giving the rest to other well performing colleges ought to be an option. But not many regionals seem to be following this, this is a huge loss to the community.

With the selection of online round questions being a little queer, and selection criteria becoming a tight leash, ICPC is losing its sheen in my opinion.

Wrong Judgement Regarding Compression Algorithm (ICPC 2017)

$
0
0

Issue :Wrong Judgement Regarding Compression Algorithm (ICPC 2017)

We have checked our code against an AC code of my friend on many randomly generated test files and checked the absolute error of 10^-6 and our code passes every file generated.

I was continuously getting WA on the solution which was first submitted 1 hour 53 minutes into the contest.Due to this we could not attempt further questions in-spite of having 1.5 hours remaining.

This seems a serious issue regarding ICPC selection procedure and appears to be a problem with many other contestants. So I would request Codechef to look into the matter seriously and get the results updated.

Submission Id (in case @admin wants it):16117665

"I want to ask a question" - Ask them all here!

$
0
0

Hello guys,

As you all are aware, many times there are genuine users who wish to ask a question, but dont have karma for it. They then, have to resort to means of either asking their question in other threads, or request someone to upvote them so they can ask a question.

As we have seen last month, some fake accounts were used in malpractices in discuss, and they also gained karma by "I want to ask a question" thing. Hence, now it is becoming increasingly difficult to differentiate between genuine users, and fake users.

This thread is my solution for it. Any user, with less than 3 karma who wants to ask a question is requested to ask it here, and if the question is upto standards (meaning it needs more than those "one line answers") then we (at least I ) will convert your "answer" here into a question.

In short, post your question here, and if its a good genuine question, it will get posted as a separate question by using "Convert to question" feature.

In case your question required only 1 line answers or such, we would comment it on your question.

You guys are requested to direct any such guy (who wants to ask a question) here and not "free-upvote" them, so that we can avoid any duplicate/irrelevant questions (as questions posted here would be verified first, before converting to question).

Note to @admin - We will require your active participation and help in events related to deletion of any spam content here. Also, since only admins are ones who could delete answers, it is requested that you keep an eye out on this thread.

With Regards

Vijju123


when will acm icpc 2017 online results will be published?????

$
0
0

when will ACM ICPC 2017, Online Preliminary Round online results will be published?????

Skiing unofficial editorial november cook off

$
0
0

problem:Skiing

Recursive easy problem

Solution:
we have to find minimum no of boxes(let it be set S), such that i can visit any other box in grid by choosing any starting box from that set S.

For getting out maximum no of visit from a box we will choose the box with maximum height, and we will mark all the adjacent boxes which can be visited from that box.
we will keep doing the same until all the boxes are visited and count the no of times we have to do this work.

i will be choosing maximum value which is unvisited all the time.

for getting maximum heights i have maintained a priority queue, solution is easy u can understand it easily.. this is something like flood filling..

mysolution: solution

share ur views in the comment box. :)

November Cook-Off

$
0
0
   #include<bits/stdc++.h>
#define ll int
using namespace std;
int main()
{
    int t;cin>>t;while(t--)
    {
        ll n;cin>>n;
         vector <string> colour(n+1);
          vector <string> israted(n+1);
           vector <ll>rating(n+1);
            vector <ll>mini(n+1);
             vector <ll>maxi(n+1);
              vector <ll>tim(n+1);
              ll ar[n+1];
              for(int i=0;i<n;i++)ar[i]=0;
              for(int i=0;i<n;i++)
              {
                  cin>>rating[i]>>mini[i]>>maxi[i]>>tim[i]>>israted[i]>>colour[i];
              }
              for(int i=0;i<n;i++)
              {ll fail=0;
                  for(int j=0;j<i;j++)
                  {
                      if(i==0){cout<<"wait"<<endl;break;}
                      else{if(tim[i]==5||tim[i]==15||tim[i]==30||tim[i]==60&&(tim[j]==5||tim[j]==15||tim[j]==30||tim[j]==60)&&(colour[i]=="white"||colour[i]=="black"||colour[i]=="random")&&(colour[j]=="white"||colour[j]=="black"||colour[j]=="random")&&(israted[i]=="rated"||israted[i]=="unrated")&&(israted[j]=="rated"||israted[j]=="unrated")){
if(rating[i]>=mini[j]&&rating[i]<=maxi[j]&&tim[i]==tim[j]&&israted[i]==israted[j]&&((colour[i]=="random"&&colour[j]=="random")||(colour[i]=="white"&&colour[j]=="black")||(colour[i]=="black"&&colour[j]=="white"))&&ar[j]==0){
    cout<<j+1<<endl;ar[j]=1;fail++;break;
}
                      }}
                  }if(fail==0)cout<<"wait"<<endl;
              }
    }
}
What's wrong with it?

RNDPAIR - Editorial

$
0
0

Problem Link

Practice

Contest

Setter:Hasan Jaddouh

Tester:Amr Mahmoud

Editorialist:Bhuvnesh Jain

Difficulty

CAKEWALK

Prerequisites

Probability, Looping techniques

Problem

Find the probability of chosing pair $(i, j), i < j$ such that $A[i] + A[j]$ is maximum.

Explanation

The probability of any event is defined as

$P(event) = \frac{\text{number of favourable outcome}}{\text{total number of outcomes}}$

The total number of outcomes is $\frac{N * (N-1)}{2}$, where $N$ = size of array. To calculate the number of favorable outcomes, we can first do a brute force over all pair $(i, j), i < j$ to get the maximum value possible and then again do a brute force to calculate the number of times the maximum is attained.

The complexity of the above approach is $O({N}^{2})$. This will easily pass the test cases as constraints are low. To solve the problem in $O(n)$, we observe that maximum is obtained when 2 most maximum elements of an array are added. Thus, it boils down to calculating the frequency of them and then finding the number of favorable outcomes in $O(1)$, using the formula:

Favourable outcomes = $f2$, i.e. frequency of second maximum element, if maximum element occurs only once.

OR

Favourable outcomes = $\frac{f1 * (f1-1)}{2}$, if maximum element has frequency greater than 1.

Time Complexity

$O(N^2)$, or $O(N)$ per test case.

Space Complexity

$O(N)$

Solution Links

Setter's solution

Tester's solution

Editorialist's solution

SKIING - Editorial

$
0
0

Problem Link

Practice
Contest

Setter:Hasan Jaddouh
Tester:Amr Mahmoud
Editorialist:Bhuvnesh Jain

Difficulty

EASY-MEDIUM

Prerequisites

Strongly Connected Components, Bfs / Dfs

Problem

Find the minimum number of cells to select in a matrix so that we can reach every cell from it through a series of moves which is, "You can move from one cell to another only if they are adjacent (i.e. share a side) and the height of destination cell is not more than height of current cell."

Explanation

The edges in the graph will be between cells $(i, j)$ and $(x, y)$, only if they share a side. Also, the edges will be directed as the edge exists from a cell into another only if the height of destination cell is not less than the height of the current cell.

For example in the sample input 1, the edges will be as follows:

Now given a directed graph, we want to select a set of cells so that all cells are reachable from it. The first observation is 2 decompose the graph into Strongly connected components, as there may be cycles in the graph. This is because all the vertices in a cycle can be visited by starting from any vertex.

Now, we have a directed graph in which there are no cycles. (It is also called a DAG). In this graph, we claim that we chose only vertices with indegree $0$ to be in our set as the possible candidate solution.

Reason : Let us say there is an edge $P$ to $Q$ in the DAG. Let us denote the set of vertices reachable from $Q$ to be $S$. Then all vertices in $S$ are also reachable from $P$. But $P$ is not reachable from $Q$. So continuing this process, we will see that only vertices having indegree $0$ are not reachable from any other vertex but they as a set cover all the vertices reachable from it.

The DAG of input sample 1 is give below:

In the above figure, $1$ represents the set ${1}$, $2$ represents the set ${2,3}$, $3$ represents the set ${4,7}$ and $4$ represents the set ${5,6,8,9}$.

Thus, the algorithm is as below:

  1. Construct the directed graph from the grid. Complexity is $O(N * M)$. Also, the number of edges in the graph is bounded by $(8 * N * M)$ as each cell can have at most 4 neighbors and it can have edge in both directions.
  2. Decompose the graph into one with no cycles. You can use Tarjan's algorithm or Kosaraju algorithm for this step.
  3. Find the number of vertices with indegree $0$ in DAG.

Author's Solution

The solution counts the number of components having same heights, such that all adjacent components are less (strictly) than it.

Proof: Each such component consisting of all cells of same height can be represented by 1 cell only. Now, each component can either have all adjacent components less tha it or not. If all cells adjacent to it are smaller, the those can be reached from the current cell, so they are ot counted towards the answer. If we repeat this process, for each component, we are bound to find only those cells which will contribute to the answer. Also, if we assume some cell that shouldn't be in answer was counted by above process, the it would contradict the fact that all adjacent components are lesser than it.

The above process can be simply implemented by a dfs call from every vertex and check if all components adjacent to it are smaller than it or not. For details, refer to author's solution.

Time Complexity

$O(N * M)$, per test case.

Space Complexity

$O(N * M)$

Solution Links

Setter's solution
Tester's solution
Editorialist's solution

Viewing all 39796 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>