Блог пользователя Morphy

Автор Morphy, история, 6 лет назад, По-английски

Code Jam R2 starts in ~24h (Saturday, May 19th 14:00 UTC)

Let's discuss the problems after the contest!

  • Проголосовать: нравится
  • +236
  • Проголосовать: не нравится

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится -77 Проголосовать: не нравится

ok

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится +81 Проголосовать: не нравится

I wonder what the exact scoring rules are.
They were not important in Round 1, but are important for me and people of my level now, in Round 2.

Case 1:
Attempt 1. Solve Small correctly and Large incorrectly.
Attempt 2. Solve Small correctly and Large correctly.
I think I get +1 penalty here, no doubt.

Case 2:
Attempt 1. Solve Small correctly and Large incorrectly.
Attempt 2. Solve Small correctly and Large incorrectly.
But do I get +1 penalty here? (I hope not, it would be nonsense, but let's wait for approved answer)

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +97 Проголосовать: не нравится

    There is a section explaining the scoring system in the FAQ. ( https://code.google.com/codejam/resources/faq )

    They take in consideration your earliest attempt that passed the visible tests, and your latest attempt, and give you points/penalty based on the better of the two.

    So for your examples, you would get +1 penalty in Case 1, and get no penalty in Case 2.

»
6 лет назад, # |
  Проголосовать: нравится +58 Проголосовать: не нравится

BUMP! Round starts in less than 30 minutes. Good luck and have fun! :)

»
6 лет назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

Why this shows round 3? https://codejam.withgoogle.com/2018/

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится +75 Проголосовать: не нравится

I'm writing my address and all those stuffs just to start the contest. I already wrote this about 5 times when taking 2018QR, and now I have to write this in the middle of the contest? If you don't want to give me t-shirts, then do it in the fair way.

»
6 лет назад, # |
  Проголосовать: нравится +24 Проголосовать: не нравится

Can someone please fix the contest? It keeps showing 20 hours for Round 3. If I go to Past Contests, I can see problems from Round 2, but I can't fu**ing submit !!!!!!

Anyone from Google around? This is unacceptable!

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +30 Проголосовать: не нравится

    idk, try a different browser or change time on your computer (it does affect some websites)

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +14 Проголосовать: не нравится

    Google doesn't care about CF (or particularly about competitive programming in general), you should write to the Codejam Google Group. Although I don't know how much requests there are watched...

    One guy had broken round 1C, the dashboard ignored timezones and had the round "start" 2 hours earlier — the problems weren't visible for those 2 hours, so he had 30 minutes to compete. This bug only happened at one computer, but it was pretty persistent (restarting browser or cache clean didn't work).

  • »
    »
    6 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +24 Проголосовать: не нравится

    they don't want to fix it, I emailed them about the issue last round as my contest ended after 1:30 instead of 2:30.

»
6 лет назад, # |
Rev. 3   Проголосовать: нравится +50 Проголосовать: не нравится

Had a lot of ideas for D, cant think of how to keep my code clean and effective .... Should've gone for small instead of going for large + AK. :/

Edit:

Me and my teammates after the contest:

Me: Whew, this is the first time I ever used the simplex template, it actually fit into B's TL!

Teammate: Isn't it DP?

Me: What?

Teammate: What?

Edit 2: So it turns out I am the only edgy kid who used simplex for B ... ?

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +17 Проголосовать: не нравится

    How did you use simplex for B?

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится +8 Проголосовать: не нравится

      Maximize dot(c, x):

      c is a column vector filled with 1, each entry of x represents if we will pick (x reds, y blues), so dot(c, x) will be the amount of jugglers we have at the end.

      Simliar to the editorial make sure you only keep pairs that are possible to be juggled with the amount of chainsaws we have.

      While satisfying Ax <= b:

      First two rows of A will be representing the constraints on how much red / blue chainsaws we have, if the i-th entry of x represents (x reds, y blues), then A[0][i] = x, A[1][i] = y. Set b[0] = Red, b[1] = Blue, such that we will never exceed the budget.

      For the i-th entry in x, to make sure we don't have jugglers which share the same juggling arrangement, add extra rows where A[i+2][i] = b[i+2] = 1.

      Code:

      https://ideone.com/VA2Uvw

      Simplex template credit goes to MIT 2008 ACM template.

      • »
        »
        »
        »
        6 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        Can you please elaborate a little on last part to ensure that we don't have jugglers sharing same arrangement?

      • »
        »
        »
        »
        6 лет назад, # ^ |
          Проголосовать: нравится +34 Проголосовать: не нравится

        How can you be sure that the answers from simplex solver are integers?

        • »
          »
          »
          »
          »
          6 лет назад, # ^ |
          Rev. 2   Проголосовать: нравится +8 Проголосовать: не нравится

          I am not sure about the proof -- But I suppose that the problem nature encourages the simplex solver to take pairs which spends less chainsaw to attain maximimzed real results, and taking floor shouldn't hurt.

»
6 лет назад, # |
  Проголосовать: нравится +32 Проголосовать: не нравится

239 people with 100 points... that's a lot more than last year's 7.

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Was C Augmenting Path/Max-Flow?

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится +8 Проголосовать: не нравится

For C, why the greedy idea (Let s the sum of size of maximum matching for each number, then answer = n2 - s) fail?

I regret wasting too much time on C, not realizing that D is actually easier than C.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    That's the correct answer for C.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Except it should not fail... I suppose you built a flow graph w.r.t row/column for each number?

    Meanwhile me failing to code D.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +103 Проголосовать: не нравится

    IMO C was the easiest problem today :P

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +5 Проголосовать: не нравится

    Could you explain your solution?

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится +17 Проголосовать: не нравится

      Iterate x from  - n to n. For each x, we will find the maximum number of cell with number x that we can keep unchanged. To do that, build a bipartite graph, each vertex on the left right represent a row, each vertex on the right side represent a column. Add an edge from u on the left to v on the right if a[u][v] = x. Then, the number of cell we can keep is the cardinality of maximum matching in the above graph.

      • »
        »
        »
        »
        6 лет назад, # ^ |
        Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

        I just don't why finding a maximum matching in above graph correspond to maximal independent set in original graph.

        What's the meaning of taking edge ij?

        • »
          »
          »
          »
          »
          6 лет назад, # ^ |
          Rev. 2   Проголосовать: нравится +6 Проголосовать: не нравится

          Each edge is corresponding to a cell in the original graph. In the maximum matching, no two edge coincident to the same vertex, similar to how no two chosen cells should be in the same row or column.

          Consider the following example

          0 3 0 
          0 3 0
          0 3 3 
          

          If we consider number 3, then the bipartite graph will look like the following:

          1  1
           \ 
            \
          2--2
            /
           /
          3--3
          

          One possible maximum matching is (1, 2), (2, 2) and (3, 3), which corresponding to the solution of keeping cell (1, 2), (2, 2) and (3, 3) unchanged.

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится +12 Проголосовать: не нравится

Is there any scrapper available online to filter contest results by countries at least?

»
6 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

How to solve C? I thought that we should compute minimum vertex cover in the graph where we have edges between vertex with the same color and (same row or column) but this graph is not bipartite. :(

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

B large Fail Test Case?

»
6 лет назад, # |
  Проголосовать: нравится +49 Проголосовать: не нравится

Wow, compilation error still counts as penalty attempt.

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can someone give me a hint why this code is failing in A : https://ideone.com/hVQGi2

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +14 Проголосовать: не нравится

    At this point I like to generate random input to see if it crashes.

    1
    6
    3 2 0 0 0 1
    Exception in thread "Main" java.lang.ArrayIndexOutOfBoundsException: -1
    	at Solution.run(Solution.java:207)
    	at java.lang.Thread.run(Thread.java:748)
    
»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

How to solve D?

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I think this should work:

    Notice that if you go deep enough, any fixed-size pattern can only be part of a very simple grid composed of 4 quadrants with the same colours (let's allow a quadrant to have colour None to deal with edge cases). Each such grid is formed by expanding a square 2x2 in the original grid sufficiently many times; there are at most 81 of them, so we can find all such colourings by brute force.

    Now, we can try dividing the original grid into 4 parts by a vertical and horizontal line; there are O(RC) ways to do this, we can try them all. We can also try all possible colourings. For each of these cases, we know which cells can't be in our pattern, and out of the remaining cells, we can build the largest connected component. Then we just need the maximum of all CC. Time O(R2C2).

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Using 24 = 16 coloring isn't too difficult either. You just have to expand 1x1 and 1x2 colorings to matching 2x2 coloring when checking which ones are present.

      • »
        »
        »
        »
        6 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        In the end, my implementation could just ignore colourings with None, so not even expanding anything was necessary, but using dummy objects that simplify implementation and only increase the constant factor is a good approach in many problems.

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится -8 Проголосовать: не нравится

      My python implementation TL'd on large, so sad. 100 tests x 16 colourings x R^2C^2 = 256 x 10^6. Didn't have time to generate maxtests, but was pretty sure that should fit...

»
6 лет назад, # |
Rev. 3   Проголосовать: нравится +85 Проголосовать: не нравится

Has it happened to you that a solution thats calculates all the 5002 answers and then solves each test in constant time passed the small, but not the large? What is wrong with their platform? How is that supposed to work?

Code:

Spoiler

Verdict is: AC on small, TLE on large.

Locally runs on just over 9s.

Their TL is 25s.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    There are probably many reasons why your code can get large wrong while passing small. What you have described here is definitely too less to draw any conclusions.

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится +8 Проголосовать: не нравится

      Fair enough. I've added some information to my comment.

      • »
        »
        »
        »
        6 лет назад, # ^ |
          Проголосовать: нравится +9 Проголосовать: не нравится

        OK, if that is TLE then it is definitely weird :P. Hypothetical WA could have been easily your fault.

      • »
        »
        »
        »
        6 лет назад, # ^ |
          Проголосовать: нравится +22 Проголосовать: не нравится

        Btw, I know that is irrelevant, but you can change

        for (int i = 0; i <= 500; ++i) {
                for (int j = 0; j <= 500; ++j) {
        

        to

        for (int i = 0; i <= 33; ++i) {
                for (int j = 0; j <= 33; ++j) {
        

        and your code should remain correct.

        • »
          »
          »
          »
          »
          6 лет назад, # ^ |
          Rev. 2   Проголосовать: нравится +51 Проголосовать: не нравится

          I know, I figured it out later during the contest, but I did not resubmit, due to obvious reasons XD.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +61 Проголосовать: не нравится

    Yesterday, I'm pretty sure I solved a problem by resubmitting (1B B, I was trying an alternative solution that was getting TLE sometimes). And in 2B here, I got TLE on something that was running in 4 seconds locally, even though the time limit on the server is much larger.

    Maybe they're measuring time with an hourglass or something?

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится +14 Проголосовать: не нравится

      Well, that's definitely an unpleasant experience to have during actual contest. Maybe they should pay more attention to testing their platform more thoroughly before throwing it to the world.

  • »
    »
    6 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +133 Проголосовать: не нравится

    Update: Resubmitting after the contest ended, the verdict was AC on small and large. Guess you have to submit at the right moment to do well on this contest.

    How stupid.

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится +121 Проголосовать: не нравится

      Try making some noise about it to organizers. They should be aware of platform's weaknesses. It's not only your business, we too don't want such surprises in future :D.

      • »
        »
        »
        »
        6 лет назад, # ^ |
          Проголосовать: нравится +34 Проголосовать: не нравится

        I have written an e-mail to them. I hope they will catch up with the issue, and it won't happen in the future. Thanks for the idea.

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится +31 Проголосовать: не нравится

      Damn, O(n^4) got AC? Nice.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +8 Проголосовать: не нравится

    For me, 501x501 array solution first gave MLE :) on the small test set, then exact the same code passed smaller, then gave MLE on big test set, then third time, gave WA on big test set. But WA was correct.

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Any "hacks" for falling balls? Had wrong answer but haven't figured it out yet.

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

I can't understand official solution for c. What's the intuition behind taking at most one vertex from edge AiBj?

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Getting wrong answer for B, but then I took someone else's code that was accepted, generated cases for all possible R & B and took a diff of the output with my code. Surprisingly it's the same. Edit: Figured it out, there was an overflow while calculating the dp

Спойлер
»
6 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Now, The tests are assumed that can be all maximum? In the past, there are small testcases and a few large testcases.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    In some problems in rounds 1, the constraints were in the format "3 out of 100 tests are maxtests, the rest are small", so you should probably assume all tests are equally large unless written otherwise. It makes sense if you need to pass test i to pass test i + 1.

»
6 лет назад, # |
  Проголосовать: нравится +19 Проголосовать: не нравится
»
6 лет назад, # |
  Проголосовать: нравится +47 Проголосовать: не нравится

For fucks sake, I didn't solve task because forget to put '#' in 'Case #x:'
I got WA and didn't understand why.
So, suicide is the only way.

»
6 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

For "Graceful Chainsaw Jugglers" problem, I was thinking of a greedy solution. It is as follows:

Make all possible pairs such {A,B} s.t. A+B = i. Here we iterate i from 1 to 1000, and if (R-Ak)  ≥  0 and (B-Bk)  ≥  0, then we update ans  =  (ans + 1), R  =  (R  -  Ak) and B  =  (B  -  Bk).

I got a WA, but I am not able to come up with a counter example. Any help is highly appreciated.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +4 Проголосовать: не нравится

    It doesn't work for some cases where R and B have a large difference. Depending on the order of iteration over the pairs with A+B=2, the case 39 3 might fail for example, choosing

    0 1
    1 0
    0 2
    2 0
    3 0
    4 0
    5 0
    6 0
    7 0
    11 0
    

    But you could optimally choose (1,1), (2,1), (8,0) instead of (0,2), (11,0).

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      I see. Thank you so much! :)
      Just curious, did it come intuitively to you, or you generated some test cases and tested against an AC code?

      • »
        »
        »
        »
        6 лет назад, # ^ |
        Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

        During the contest I at first thought greedy might be correct, but after some time had the intuition that there would probably be a counterexample with larger numbers and larger difference. For actually finding a counterexample now I had to generate some test cases.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    11 11 -> 9:

    1 0
    0 1
    1 1
    2 0
    0 2
    3 0
    0 3
    4 0
    0 4
    
    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Thank you for the help, but it seems the above algorithm managed correct answer on it.

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится +33 Проголосовать: не нравится

Submitted precomputed answers for B (400kb of code):

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Is there a yahoo code jam or baidu code jam?

»
6 лет назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

This entire new UI is so weird. Has so many problems with it. Always kind of asks for logging in, even when I am logged in. Its so weird. The older platform was much better.

»
6 лет назад, # |
  Проголосовать: нравится +34 Проголосовать: не нравится

I spent 90 minutes trying to debug my code for the last problem, and it turns out I had misread the problem statement...

When it says "present in at least a googol deeper dream grids", I interpreted "present in at least one of googol deeper dream grids". After a lot of wrong submissions, I re-read the problem statement and still failed to catch my mistake. In the end, I didn't have any time left to think the harder part of problems B and C and, because of that, I ended up ranking 1200+.

I was sleepy and kinda upset because my computer clock was wrong at the start of the contest, not allowing me to submit for the first 30 minutes. But, I still think that the words "at least" shouldn't have been there. It leads to confusion. It would have been much clearer if it said "present in 10100 deeper dream grids or more".

More on the matter of the clock: It's utterly unacceptable that a competition like Google Code Jam has code that reads your computer time to tell you when the contest starts/ends instead of reading it from a Google server. I lost 30 minutes because of that laziness/stupidity from the designers of the page. I hope they fix that for the next contest, because I wasn't the only person affected by that. Just read the comments on this page alone, and there's at least one other guy.