One Point Solution

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Saturday, 18 February 2012

SRM 533: Failure

Posted on 10:24 by Unknown
It was about time I had a bad match.

Chat
The chat before coding phase was more interesting than usual because Google engineers were in their lobby room and received questions. Google sent many widely known names in algorithm contests to represent them. What is clear is that google really pay attention to these silly algorithm contests at the time of employing new people. Hopefully TC will release a transcript of all the questions.

Div1 500 - The one with common rows and common columns
This problem beats me. I spent all the match trying to get a viable idea for it that I can prove. It seemed that it would be easy to submit a wrong idea. I kept getting lost in dead ends such as trying to find "something with flow" to solve it. A lot of people submitted a solution to it, which increased the amount of tension during the match for me.

Div1 250 - The one with energy
You have a vector of at least 3 elements. You gain score by removing an element that has an element to its left and an element to its right and then the product of these two other elements is added to your score. Return the maximum possible score.

First of all, since the numbers are always positive, the final vector will always be one in which only the original extremes are left. In other words, for 1,2,3,4 , the last vector will always be {1,4}.

Given a vector, {1,2,3,4,5,6} we know that the last operation will involve multiplying 1 and 6. The trick is to consider this last move. So, let's pick the last element we will remove: If we decide to remove 4 last, this means that we removed all elements that are not the extremes and are not 4 before this last move: {1, .. 4, ... 6 }. Now notice something else, In the previous steps, 1 and 4 and 4 and 6 won't get removed. Imagine the vector split in two parts: {1, 2, 3, 4} and {4,5,6} . We have to pick the best strategy to remove 2,3 or 5. We can treat these two cases as sub-problems of the original problem, because all of the elements are contiguous.

Thus, whenever you have an array with more than 2 elements. Iterate through all the possible elements we can remove as the last step. This will create two subproblems identical to the first. A recurrence comes from this observation, and since the elements will always be contiguous for each subproblem, you can just use dynamic programming.

struct CasketOfStar 
{
vector<int> weight;
int mem[50][50];

int rec(int a, int b)
{
int & res = mem[a][b];
if (res == -1) {
res = 0;
// Pick c - the element we will remove last:
for (int c=a+1; c<b; c++) {
// if we remove c last, we can find the score of the sub-vector a..c
// and c..b to know the best strategy for the previous elements.
res = std::max(res, weight[a]*weight[b] + rec(a,c) + rec(c,b) );
}
}
return res;
}

int maxEnergy(vector <int> weight)
{
this->weight = weight;
memset(mem,-1,sizeof(mem));
return rec(0, weight.size() - 1);
}
};


I had issues during the match. Although I thought of the general solution idea quickly. I didn't have it all figured out until after I began coding. So I had to do many corrections and think things through again. Was nervous because I switched to this problem late and I already knew a lot of people had solved both the medium and this problem.

Challenge phase
A lot of solutions failed during challenge phase. Seems 500 was easy to get wrong. I am not even sure I will pass 250 because there might be a mistake somewhere.

What do you think?
Did you like the match? I think the problems were interesting. I wish I was more creative and able to think the solution for 500.

Update: outcome
I like the outcome. I dropped around 30 points in rating, which is not a big deal. I still have more than 2100 points. A rating drop was bound to happen, and it is always nice when it happens lightly.
Email ThisBlogThis!Share to XShare to Facebook
Posted in badday, google, srm, topcoder | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • TopCoder SRM 557 - finally
    SRM 557 Explanation for division 1 Easy and match recap. Explanations for div2 easy and div2 medium. It feels like it has been ages since t...
  • SRM 589 Editorial
    I have finished writing the editorial for TopCoder SRM 589: http://apps.topcoder.com/wiki/display/tc/SRM+589 . As you most likely noticed. L...
  • SRM 590 recap and editorial
    Another week another Topcoder match. Not a great day. I had a bad flu and still do. Div1 500: The one with Xor Given a list of cards with nu...
  • SRM 546: relief
    I figured I should post something about this SRM. I've been very busy these weeks because the semester is ending and I tried to win a t-...
  • SRM 526: The killing wait for results
    While I wait for results, here is my perspective on this algorithm contest. It began with issues, it had to be postponed 15 minutes. TC has ...
  • SRM 554 div1 hard: TheBrickTowerHardDivOne
    Link to problem statement We got infinitely many bricks of dimensions 1x1x1 and C different colors. Count the number of towers of size 2x2...
  • SRM 533: Div1 500 MagicBoard explanation
    Finally solved it. It is a nice problem that is worth explaining in a post. You have a grid/board of at most 50x50 cells. Some cells contain...
  • Member SRM 505: Part 1
    So, let me explain a couple of problems from a Topcoder Member SRM that I wrote and never got an editorial. BTW, it was the last member SRM....
  • ListedLinks 2012-02-10
    Saturday Morning Breakfast Cereal comics: Grace Hopper's ghost That Oracle engineer blog post Oracle would really not like anyone to se...
  • Codeforces "Good bye 2013" round
    So it was a special round for coders of both divisions, problems ranged from the super easy problem A to the super difficult problems E,F,G....

Categories

  • acm
  • algorithm
  • answers
  • arenaplugin
  • badday
  • behindthescenes
  • bugs
  • c++
  • censorship
  • codechef
  • codeforces
  • contests
  • crocchamp
  • editorial
  • editorial.srm
  • embarrassing
  • explanation
  • gcj2013
  • gmp
  • goodday
  • google
  • googlecodejam
  • greed
  • groklaw
  • health
  • html
  • httpseverywhere
  • implementation
  • ipsc
  • ispc
  • java
  • kawigiedit
  • kindagoodday
  • lamebook
  • languages
  • lego
  • listedlinks
  • marathon
  • nasa
  • offtopic
  • ouch
  • postmortem
  • postportem
  • practical
  • probably_not_a_good_tip
  • problemsetting
  • programming
  • python
  • quora
  • rant
  • recap
  • slightlygoodday
  • snippet
  • srm
  • stl
  • strategy
  • swerc
  • tco
  • tco12
  • tco13
  • tco2012
  • tco2013
  • ternarysearch
  • topcoder
  • tricks
  • ubuntu
  • uva
  • vjass
  • vkcup
  • wc3
  • zinc

Blog Archive

  • ►  2014 (1)
    • ►  January (1)
  • ►  2013 (141)
    • ►  December (14)
    • ►  November (8)
    • ►  October (13)
    • ►  September (11)
    • ►  August (14)
    • ►  July (15)
    • ►  June (13)
    • ►  May (13)
    • ►  April (12)
    • ►  March (11)
    • ►  February (11)
    • ►  January (6)
  • ▼  2012 (94)
    • ►  December (5)
    • ►  October (6)
    • ►  September (8)
    • ►  August (6)
    • ►  July (3)
    • ►  June (5)
    • ►  May (8)
    • ►  April (10)
    • ►  March (20)
    • ▼  February (16)
      • It is the old and worsened ListedLinks 2012-02-27
      • ACM 2012 World finals warmp up I
      • Codeforces 109 1B / 2D - Colliders
      • SRM 534: Div1 500, EllysNumbers
      • SRM 534: Notes that contradict the problem statement
      • Codeforces round #108
      • What is it like to be a (topcoder) problem setter?
      • SRM 533: Div1 500 MagicBoard explanation
      • SRM 533: Failure
      • Codeforces round #107 : "undefined"
      • ListedLinks 2012-02-16
      • Google autocomplete awesomeness
      • ListedLinks 2012-02-10
      • SRM 532: Easy problems can be evil
      • ListedLinks 2012-02-04 - Censorship edition
      • ListedLinks 2012-02-02
    • ►  January (7)
  • ►  2011 (51)
    • ►  December (7)
    • ►  November (12)
    • ►  October (5)
    • ►  September (1)
    • ►  August (3)
    • ►  July (4)
    • ►  June (3)
    • ►  May (7)
    • ►  April (3)
    • ►  March (2)
    • ►  February (1)
    • ►  January (3)
  • ►  2010 (9)
    • ►  December (4)
    • ►  October (1)
    • ►  June (1)
    • ►  May (1)
    • ►  January (2)
  • ►  2009 (1)
    • ►  December (1)
Powered by Blogger.

About Me

Unknown
View my complete profile