One Point Solution

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

Saturday, 23 February 2013

Topcoder Open 2013: Round 1A

Posted on 10:46 by Unknown

As I begin to write this during the intermission phase, it appears that I did well and solved the three problems. But I am really not sure about the medium I coded. And dumb mistakes are always possible.

I forgot to mention that, since Tournament matches (unlike SRMs) are not practice, I am not going to use my suicidal strategy during these matches. But I think that I I advance to round 3, my only chance to advance at all would be to solve the hard problem, so if I get to round 3, I will open ONLY the hard problem, maybe I get lucky and advance (Yeah right).

250: The one with heights.

You are given a matrix of up to 50x50 heights , each height is from 0 to 9, you can increase or decrease each height any number of times. The objective is for the difference between maximum and minimum height to be at most 1 after you decrease/increase. Return the minimum number of steps (increase/decrease) needed.

Simple! One height of the final matrix got to be the minimum height, and this height is from 0 to 9, so just try each of these 10 values for the minimum height. Then each of the heights has to be between minimum and minimum+1, so it is easy to calculate the minimum cost to make the height fall in that interval.

500: The one with jumps.

You want to jump using leaps of width X starting at a point 0, and up until D or any point greater than it. The catch is that there are many pits, and for each pit i, the space between L[i] and R[i] are impassable (Not inclusive, so L[i] and R[i] are good to stand in), return the minimum X.

The first thing to notice is that we can do D = R[n-1] and everything will be good.

At first it seemed that as long as the last leap fell in R[n-1] it would be fine, so I solved with that assumption and I even passed examples. I passed examples long after spending a good time debugging the solution, so I forgot that I was supposed to actually make sure that the R[n-1] condition was true. I submitted it and then my brain reacted... wait. So it turns out that the case : D=6, L={0,4}, R={3,5} this would be wrong. It is not a good idea to fall in position 5, the best result is 3.

But that challenge case made me notice the real condition: At some point the leap should touch one of the values of R[i]. It makes sense but it is hard to prove. So I just tweaked the solution I already had to make it try all values of R[i] instead of the last one. Time out seemed a risk, but it seems fine.

Anyway, let us say you want a leap that falls in R[i], then you got to first verify that leaps of width R[i] will not have an issue), then you can try R[i]/2, R[i]/3, ... and so and so until R[i]/R[i] and see if any of those leaps also work. Remember the minimum.

For some odd reason, at a point during debug I decided to use fractions instead of doubles. I think it is overkill the bug I was having was not related to precision.

And to check if a leap of width X is possible, you can just try for each pit : If there is a integer r such that: r*X is between L[i] and R[i] then it is wrong.

1000: The one with arrows

You got a matrix of up to 15x15 directions (up, down, right, left). The objective is to change the contents of the matrix so that, no matter what cell you start at, you will always eventually return to the initial position, by always moving to the cell pointed by the direction of the current cell you stand at. The rows and columns are cyclic.

I am not sure why, but I noticed "this is max flow" right a way. I just didn't know how to do it until some thought work.

The trick is that , the objective is fulfilled if and only if for each cell x: There is one cell that points to cell x. Try it. Then we can solve this using min cost perfect bipartite matching: For each cell, assign a target cell to it, each cell must have only one incoming and outcoming cell. If the initial direction of a cell is LEFT, then it is free to assign the cell to the left, else the cost is 1. And so and so for each direction.

Comments?

I plan to make the editorial as quickly as possible to have a free schedule.

Email ThisBlogThis!Share to XShare to Facebook
Posted in explanation, tco, 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)
      • Topcoder open 2013, 1A editorial
      • Topcoder Open 2013: Round 1A
      • SRM 571 editorial
      • TopCoder SRM 571: Educative
      • TopCoder SRM 570 Editorial is ready
      • TopCoder SRM 570: CentaurCompany and CentaurCompan...
      • Topcoder SRM 570 -"CurvyonRails" Editorial
      • SRM 570: Blue
      • SRM 569 Editorial
      • SRM 569 editorial preview
      • SRM 569 : Blunder
    • ►  January (6)
  • ►  2012 (94)
    • ►  December (5)
    • ►  October (6)
    • ►  September (8)
    • ►  August (6)
    • ►  July (3)
    • ►  June (5)
    • ►  May (8)
    • ►  April (10)
    • ►  March (20)
    • ►  February (16)
    • ►  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