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

Автор riadwaw, 12 лет назад, По-английски

You need to get 20 points in order to advance to Round 1.

Post about entire GCJ

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

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

I can't see the comments. Is it a bug, or a feature?

EDIT: I can see this comment, but I can't see other user's comments. I can see comments normally on other blogs.

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

please someone explaine me how you can put the 4 shape in line 2 in 3*6 grid(for example) http://upload.wikimedia.org/wikipedia/commons/thumb/a/aa/All_18_Pentominoes.svg/220px-All_18_Pentominoes.svg.png

because a lot of solutions like eatmore solution he put case 5: gabriel = min(r, c) >= 4 || (min(r, c) == 3 && max(r, c) > 5);

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

In Dijkstra, tourist has performed this step:

const int MAGIC = 42;

if (X > MAGIC) {
  X -= (X - MAGIC) / 4 * 4;
}

Can someone please explain why the reasoning behind this step?

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

    If you have a large number of copies of the initial string (in particular, 42 is big enough) then in one of the three parts you must have a substring in the form SSSS for some S. But any quaternion raised to the power of 4 returns 1, so we can remove that string from this part. Therefore, if X is sufficiently large, we can subtract 4 from it and get the same result. So what tourist is doing here is changing X to the smallest number above 42 that is the same as X nor 4.

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

    Observe that anything ^ 4 = 1. Therefore each part is would not be longer than 4 repeats.

    During the round I used 12 as the magic number but I also tested 4 on the small and large-practice and it is also correct.

    if (x > 4) {
      x = 4 + x % 4;
    }
    
  • »
    »
    12 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +65 Проголосовать: не нравится

    btw, seems 5 is enough (at least for my test data).

    My sad story:

    I though 8 is enough (because their are 1,i,j,k,-1,-i,-j,-k). But when I downloaded the data, I was gready: oh what if my proof(guess) is wrong, let's use 16, if it is too slow then change back to 8. And that is super fast, I'm very happy and submitted.

    But it failed because the size of array is not enough when I change 8 into 16. >_<

    Lesson: don't make stupid decision after download test data..

»
12 лет назад, скрыть # |
 
Проголосовать: нравится +28 Проголосовать: не нравится

How many people failed this testcase for D: 5 3 5?

»
12 лет назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

Solution for B

Observe that the optimal solution is always: distribute pancakes to empty plates using special minutes, such that everyone has at most X pancakes. Then spend X minutes to eat those pancakes.

Let's brute force X from 1 to 1000. In each try, if a person i has more than X pancakes, we would need ceil((Pi - X) / X) extra special minutes to distribute pancakes. Sum up those special minutes and add X eating minutes, that would be the total time. Output the minimum of such total time in all X.

ceil((Pi - X) / X) can be rewritten as (Pi - X + X - 1) / X = (Pi - 1) / X.

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

Is there any way to filter standings by country?

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

how to solve large input version of Dijkstra problem ?

  • »
    »
    12 лет назад, скрыть # ^ |
    ← Rev. 5  
    Проголосовать: нравится 0 Проголосовать: не нравится

    You can notice that any signed letter ^4 equals to 1. So we may have periodicity when X > 4. Maybe we can use that to do less processing. If X <= 4 we can just solve it as if we were dealing with small case: one approach is to find first occurrence of i, a later occurrence of i*j and check if the whole multiplication is i*j*k.

    Lets split the given string |S| = L in pieces by its periods. If X > 4 we have to consider that even if ij occurs before i in the first piece, it may occur in the second piece after i. We could process 'til 4*L and check if i and ij occurs somewhere. But it does not guarantee us that there will be a i before a ij in the given multiplication. We could have X = 6 with ij occuring in the last part of S and i occuring right after it. Then we would not have i before ij even if the string is periodic, because it wasn't periodic at all (we had a single complete period and an incomplete period). But if we assume we have two complete periods, this logic will work.

    So we process as if we were dealing with small cases for X <= 8 (at most two complete periods) and process splitting string in pieces for X > 8.

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

    I didn't come up with idea that fourth power gives one for any letter so my idea for this problem was slightly different, though I decided not to implement it and go sleep instead. The idea is that you can greedily find left and right pieces (the shortest prefix which gives 'i' and longest suffix which gives 'k'). Then all you need to check is whether the string between them gives 'j' and I was going to do that using something similar to binary exponentiation.

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

Can anyone explain how we can we solve this 5 3 10 when richard chooses this omino ?

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

Dont you think that problems this year was harder than lasts year? Personally I scored 37 points,and last year where I knew nothing about competitive programming I scored 55 points. Also I saw some statitics and this year passed much less programmers than last season.

I hope Round 1,to be as usual,beucause if it is harder than usual then I have no hopes :P. What do you think guys?

»
12 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится +63 Проголосовать: не нравится

My solutions for C+D are fairly different from the mainstream. I guess I didn't like doing casework ;)

In C, we can note that the "Dijkstra language" is regular. There is a simple non-deterministic automaton with 24 states that recognizes it. Each state is a tuple (number,quaternion) where number is the segment we are in (0 if we are still reading the part that will reduce to i, 1 for j, 2 for k), and quaternion is one of 1,i,j,k,-1,-i,-j,-k: what the current part reduces to.

Easy input: simulate the automaton. Hard input: Simulate the automaton on a single copy of the input string for each starting state, then use fast exponentiation in O(log X) to simulate it on X copies of the string.

D: For X >= 7 Richard wins (by using the 7-omino with a hole), otherwise we can just use brute force. For large R,C with RC divisible by X Gabriel will always win anyway and there are plenty of ways to do so ( => our code is fast ) and for small R,C the number of possibilities is small ( => our code is fast again ). The only optimization needed: when simulating Gabriel, make sure you immediately backtrack from unsolvable states -- ones where some connected component of empty cells isn't divisible by X. This is a useful trick in many tiling problems.

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

    Fast exponentiation is not really needed, as only X % 4 matters.

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

      That's precisely my point. Why bother thinking about whether x%4 works and whether or not there are special cases with that (e.g., is 0 the same as 4?) if you see a solution that is simple to implement and obviously has no special cases?

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

        if(X > 20) X =20+X%4

        I'm as sure as I care to be at the time I'm solving the problem (what is sleep?) that it works — and it's just one line. I just want to send something — quickly — so that I'd have a peace of mind and sleep. That's one case :D

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

        While I definitely agree with the "don't do thinking that your code can do for you" sentiment, I think that the mainstream solutions for C were the way to go here. They can be summed up as:

        1. Check if the whole product is -1 in log(X) time.
        2. Run the simple, 5-line, partial sum solution for a constant number of copies. You can make this constant equal to, let's say, 100 without having any problems and it's obvious that it works without doing any detailed analysis on residues.

        Don't get me wrong, the automaton solution is more insightful and it is beautiful, but I don't think it supports the "keep it simple" argument in this case.

        One could also argue that a little more (not complicated) analysis can spare you a lot of code in D (although going pen and paper all the way can be risky).

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

          Well, "simple", just as "beautiful", is in the eye of the beholder :)

          There is no single right way to go. Each of us has different goals and priorities.

          (And btw, once you know the product of a single copy of the string, you can easily check whether the whole product is -1 in O(1) time, if you want to. And it's less code again, if you want to go that way.)

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

    Regarding problem D. I'm surprised that even tourist used "manual" if-if-if-if approach. My "algorithmic" solution is similar to yours one, but without brute force for Gabriel. So,

    1. Generate all the possbile figures
    2. Iterate through all the figures
    3. To check, whether it is possible to use selected figure — iterate through all possible positions for this figure on the grid
    4. If for some position the grid is divided to connected components with sizes X*K, the figure is "solvable". Do not try to split the grid using brute force — just believe, that it is possible :)
    5. If there is an "unsolvable" figure, Richards wins, otherwise — Gabriel wins

    I didn't strictly prove statement 4 (I didn't even try, since didn't have paper and pen :D ), but it seems that it may be incorrect only for significantly larger sizes than 6 (I expect problems starting from sizes about 14-16)

    So the solution is O(number_of_figures * (R*C)^2)

    • »
      »
      »
      12 лет назад, скрыть # ^ |
      ← Rev. 3  
      Проголосовать: нравится +147 Проголосовать: не нравится

      This is not a valid position, although only one connected component of size 18 needs to be tiled (X=6 on a 4x6 grid):

      ......
      .X.X..
      .XXX..
      .X....
      
      • »
        »
        »
        »
        12 лет назад, скрыть # ^ |
         
        Проголосовать: нравится +32 Проголосовать: не нравится

        Good catch!

        And a good thing that it still does not affect the answer for the problem, since there are always more fortunate placements.

        Otherwise, most iffy solutions would also fail to catch something as involved as this.

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

      I don't understand why are you surprised that someone used one approach not another one. For me considering all the cases was pretty fun and it's just qualification round, it can be used to have some fun and writing a backtracking solution is definitely not good way to get it :) (typically, I hate casework, but in this problem it was amusing for me :P).

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

        Casework was so boring for me I decided to do small manually (there are only 64 cases after all -- if you reduce symmetry and obvious cases, even less), but the casework for large looked pretty difficult to prove and not really intuitive -- I don't know how to easily eliminate things such as the case fram showed, for instance, or staircases.

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

          For large, to do casework, you need some observation like:

          • If you can fill a board of size 3*5 with any 5-ominoes, then you can fill a board of any bigger size R*C (of course R*C is divisible by 5).
          • If you can fill a board of size 3*6 with any 6-ominoes, then you can fill a board of bigger size.

          After this, for each 5-ominoes, draw 3*5 board that contains it. After this fail for the staircase thing, you don't even need to redo the other 5-ominoes because those 3*5 boards can be easily converted to 4*5. The same applies to 6-ominoes.

          It took me around an hour to solve 5 & 6. But I think coding + debugging could have taken more time for me.

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

          I didn't understand, 3 ifs was too much for you, so you decided to solve 64 ifs?

»
12 лет назад, скрыть # |
 
Проголосовать: нравится +48 Проголосовать: не нравится
»
12 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

My submission for B was judged as incorrect could you help ?

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

What I feel right now:

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

Do you know if googlejam write its editorial "fast"(1-2 days after contest) ? I need them for "qualification rounds" and I will need them for Round 1 too. They will post them soon or after whole googlejam is ended?

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

Oops, eduardische saw it first!

»
11 лет назад, скрыть # |
 
Проголосовать: нравится +98 Проголосовать: не нравится

By the way, is there anyone else think task C "Dijkstra" should win the "Best Background Story Award"? :P

The Dutch computer scientist Edsger Dijkstra made many important contributions to the field, including the shortest path finding algorithm that bears his name. This problem is not about that algorithm.

You were marked down one point on an algorithms exam for misspelling "Dijkstra" -- between D and stra, you wrote some number of characters, each of which was either i, j, or k. You are prepared to argue to get your point back using quaternions...
  • »
    »
    11 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +15 Проголосовать: не нравится

    Yes, I also laughed very hard on this one :D. It is even more hilarious that people in fact very often quarrel about how to pronounce this "ijk" :D. I heard versions "Dikstra", "Dijkstra", "Dajkstra", "Daejkstra" (pronounced in polish). And those quaternions fits there so well :D!