CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Wiki » October 2011 Contest Problem Editorials

October 2011 Contest Problem Editorials

 

 

Problem Tester for the October 2011 Contest was Harsha S.

-------------------------------------------------------------------------------------------------------

BAKE (written by Anirban Mitra)

 

This problem presents a typical OLAP problem scenario with multiple dimensions with each having an hierarchy of levels. In this problems the dimensions were product, location, gender and age. The level hierarchy for the location dimension, for example, is country->province->city->region.

The expected solution for this is to pre-aggregate the sale information at different levels of dimensions so that queries can be efficiently answered. The combinations of levels of each dimension at which a query can be asked are as follows

product_id.product_size, country.province.city.region, gender, age
product_id.product_size, country.province.city, gender, age
product_id.product_size, country.province, gender, age
product_id.product_size, country, gender, age
product_id, country.province.city.region, gender, age
product_id, country.province.city, gender, age
product_id, country.province, gender, age
product_id, country, gender, age

So, pre-aggregate the data at all these levels. For example, say for the combination {product_id, country.province.city, gender, age} there is a 4-dimensional matirx, say mat, where mat[PID][CITYID][GID][YRS] keeps the totals sales for the product with id PID, in city with id CITYID, done by person of gender GID of age YRS. Similarly, maintain a matrix for the the combinations because a query can only ask about sale information at these levels. Hence, for a single input, you will have to update multiple matrices at all the appropriate matrices.

But because for the fourth dimension, i.e. age, there can be range queries that is give me the sum for age START_AGE to END_AGE. So, for the fourth dimension, I used Binary Indexed Tree (BIT) to maintain range aggregates. They are easy and efficient to both update and query.

 

You can view the solution here:

Problem Testers' solution

Problem Setter's solution

-------------------------------------------------------

DISHDIS (written by Vamsi Kavala)

 

This was the Easy problem for this month. The problem is a standard combinatorics problem which asks us to find the number of solutions possible for:

x1 + x2 + x3 + ........ + xm = n

with the constraints ai<=xi<=bi

Though the problem can be solved using combinatorics, the constraints and the time limit of the problem allow a simple O(n3) dp solution to pass. The recurrence is straight-forward. Let dp[x][y] denote the number of ways of preparing y dishes by the first x cooks. Clearly, our answer will be dp[m][n]. The recurrence is as follows:

dp[i][j]=Σdp[i-1][j-k]      where x[i]<=k<=y[i]

A lot of people had a problem passing the time limit with a recursive solution. It's always better to write an iterative code for your solution, especially if the recurrence is simple.

 

You can view the solution here:

Problem Setter's solution

Problem Tester's solution

-------------------------------------------------------

LAND (written by Gennady Korotkevitch)

 

This problem brought a very close race into this contest. With only two hours to go, it was still unclear who would win.

Even though a lot of coders are finishing the contest with 6 points, the difference in their approaches is quite significant -- that is, even with 6 points it's still very difficult to climb up the rankings to the very top places. For example, a score of at least 0.997 could be achieved by the following very simple approach. First, fill all the empty cells with the same number, say, 25 (so that it's close to the average of the possible values). Then take any cell, try to change its value into some other value (usually just adding or subtracting 1) and see if this action improves the score (if it doesn't, undo the change); do this until there are no more cells which can be improved.

Simulated annealing is a better approach, as it allows changes which actually make the score worse with some probability -- and the earlier is the moment we try to perform such a change the higher is the probability. For more information on this approach, Wikipedia may help (or some other resource which I don't know or don't remember).

The biggest drawback of the mentioned approaches is their locality -- that is, sometimes changing the value of a cell doesn't help unless we change the values of a whole bunch of cells. So, it might be worth taking an "area" of equal values and trying to change all the values in the area (except the cells which weren't empty from the start). Trying to improve a particular row or column may also help.

 

You can view the solutions here:

Problem Tester's solution

Problem Setter's solution

-------------------------------------------------------

REPSTR (written by AnhDQ)

 

At first, it is easy to prove that if there exists a substring with the length of K (K > 1) appearing the most times, there must exist another substring with the length of K-1 appearing the same times (it is such a prefix of the substring length K). So we will find the most appearing substring with the length of L to determine the most times T (first result). Then to find the longest substring appearing T times (second result), we just use binary search to solve it.

The key of both steps is counting the number of times that a substring appears. Theoretically we can use a SUFFIX TREE to solve it (easy to find documents over the internet). However I suggest another way which is easier to code and also understand but still usable to solve this. It is using HASH. As we know it is possible to use a MAP to directly store the appearing times of any substring, but it takes a long time to find and compare the strings. So I choose to encode any given substring in the base of 26 (because we have only 26 different characters), then take the modulo of a prime key (because the value of encoding may be very large, search for documents about the technique of HASH) then use it as the key to use in mapping. Another problem is, it may be wrong comparing different substring sharing the same key, so to make the keys completely different, I use a pair of prime keys to take the modulo of. And it is enough to pass this problem.

 

You can view the solution here:

Problem Setter's solution

-------------------------------------------------------

LUCKPAL (written by Ankul Garg)

 

.

 

You can view the solutions here:

Problem Setter's solution

Problem Tester's solution

-------------------------------------------------------

PARSIN (written by Hiroto Sekido)

 

You can view the editorial here.

 

You can view the solutions here:

Problem Setter's solution

-------------------------------------------------------


Comments

  • Login or Register to post a comment.

Solution links are not there

_arjun @ 11 Oct 2011 09:03 PM
Solution links are not there

It's funny solution given by

anector @ 11 Oct 2011 11:56 PM
It's funny solution given by problem tester for the LAND.

http://www.codechef.com/OCT11

pratikmoona @ 12 Oct 2011 11:29 AM
http://www.codechef.com/OCT11/status/DISHDIS,pratikmoona Could someone please tell why all of my solutions TLEd? It was damn frustrating. Its an iterative DP, without any modulo operations! It TLEd even with fast I/O!

Why

monish001 @ 12 Oct 2011 12:11 PM
Why http://www.codechef.com/submit/LUCKPAL not working?

@pratikmoona: Try reducing

vamsi_adm @ 12 Oct 2011 03:16 PM
@pratikmoona: Try reducing the space complexity to n^2 from n^3. I guess it should work then.

Can anyone explain how

svm11 @ 12 Oct 2011 06:50 PM
Can anyone explain how Rudradev Basak got the closed form for sine partition function?

Explanation for SINE

vkjk89 @ 12 Oct 2011 07:22 PM
Explanation for SINE PARTITION problem is little tricky.Could some one please elaborate more ?

@Vamsi_adm: But the

pratikmoona @ 12 Oct 2011 08:24 PM
@Vamsi_adm: But the constraints are small enough to let an O(n^3) solution.

Can anyone tell me what was

dinemont @ 15 Oct 2011 11:34 AM
Can anyone tell me what was wrong in my solution? http://www.codechef.com/viewsolution/700008

hello admins.can u please

ankurnit @ 16 Oct 2011 02:18 AM
hello admins.can u please tell me algorithm to solve the diophantine equation like in dish distribution.i have facing challenge for solving different problems like this problem only.
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com