Изменения рейтингов за последние раунды временно удалены. Скоро они будут возвращены. ×

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

Автор ibrahim_habib, история, 4 года назад, По-английски

Hello everyone,

Soon starts round 1C of Google Codejam. It's the last subround of round 1 and the last chance for people qualified from qualification round but haven't qualified from round 1A or 1B. To qualify one has to be in the top 1500 participants in this subround.

Let's discuss the problems here (after the round is finished, of course !).

I wish you good luck in this round.

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

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

Can we submit solutions in 1C even if we've already made the top 1500 in another round? I wanted to participate for fun.

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

For B I assigned letters according to frequence of the first character of R[i].
In other words, d[i] (1 <= i <=9) is equal to the most frequent R[j][0] among all R[j].
Can anybody explain why it's correct?

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

    It's more probable to have 1 as a first character then any other. Why? You have two randomizations — one randomizes upper_bound, the second randomizes number itself. Let's check just the digits. You can see that number 1 can be achieved for every upper_bound, and number 2 cannot be achieved for upper_bound equal to 1. You can generalize it even further, I don't have a formal proof.

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

    I did exactly the same but I have no idea why my solution got WA on second test set :( can anyone help me find my bug please?

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

      Try changing int M to long long M. It's strange but helped me. I just described this case here

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

        WOW.

        I got RE on test 2, and was debugging it for at least 20 minutes. Then I gave up. Had no idea what the problem could be. It's sad to hear that changing int skip to ll skip fixes the problem.

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

        @Mindstorm Thanks, it worked :'( :'(

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

What was the intended solution for C?

I only managed the first two testcases, my solution was O(n^2 * log(n) * d), which TLEd on bigger constraints.

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

    Me too, but I think O(n * log(n) * d * d) is possible:

    Store all a[i] in a map as reduced fractions — (a[i]/1) pairs.

    Try each unique slice (s) D times — from (a[i]/1) to (a[i]/D):

    • Try all multiples of s from 1 to D O(D*log(N)) in increasing orders as we benefit from fewer slices to get s value.
    • If you need additional slices try to get them from the next D biggest that are not multiples. O(D+log(N) which is smaller than above)
  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    There are nd possible slice sizes, as you've noticed for the n^2d solution. The trick for nd^2 is to save, for each slice size, a list of the original pancakes that can create that size of slice. This can all be done in nd time plus some sorting. To test whether k cuts are possible, we only have to consider slice sizes with at least d-k pancakes in the corresponding lists. While these lists may be large, we never have to consider more than the k smallest pancakes in each, hence the runtime.

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

    I solved post-contest in $$$O(nd \log nd)$$$

    There are two things you want to know about each of the $$$O(nd)$$$ possible slice sizes: first is the maximum number of cuts you can "save" by choosing that size, second is whether it is possible to even make enough slices of that size. It's easy to obtain these properties in $$$O(n)$$$ per slice, but we can do better.

    For the first subproblem, pre-sort $$$A$$$. When generating the slice-size $$$\dfrac {A_i} k$$$, you already know $$$A_i$$$ is evenly divisible by it, so you save a cut as long as the number of slices for that size hasn't exceeded $$$d$$$ yet. A couple of hashmaps will store these statistics fine — be sure to reduce each fraction to lowest terms via the GCD before using them as keys.

    For the second subproblem, collect all generated slice-sizes, sort them (recalling how to compare fractions), then binary search for the largest slice-size that can make enough slices.

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

In problem B suppose we get input :

1
5 a
5 a
5 a
(repeated 1e4 times)

How to find the string corresponding to 0123456789 ? Since inputs are random , why above test case is wrong ? If it's correct then how can we find the string ?

Then it seems that is can have multiple answers .But was that mentioned in question ?

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

    Input is randomly chosen, it's not hand-made

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

      I have written in comment that "inputs are random" so above is possible .above input can be one of the random inputs . possibility is very less but then also it can be one of the random of inputs .

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

        you have to choose uniformly across all valid possibilities

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

          It was mentioned that probability of choosing is "uniform and random" but that does not say that above test case cannot happen . Suppose i generate uniformly between $$$1$$$ and $$$100$$$ , for $$$100$$$ times , ideally it should give $$$100$$$ different numbers , but possibility that same number occurs all $$$100$$$ times is NOT ZERO.

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

            The probability that all the numbers are same in the case you have given is $$$1/100^{100}$$$. Mathematically speaking, you will have to run the given computation at least $$$100^{100}$$$ times to get a high chance of getting all the numbers to be same.

            Practically, what is to be expected: that the $$$1/100^{100}$$$ case somehow occurred and even the tester's solution failed, or that we got an appropriate test case?

            The chances of the former happening is 1 in a Googol Squared, so I'll let you decide for yourself.

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

              "chances of the former happening is 1 in a Googol Squared" sure .thus it can occur single time in first place itself in Googol Squared computations .

              They should have mentioned this in the problem that such type of test cases won't occur .But then they can't say this because it would be opposite to uniform and random .

              I finally understood during contest that such type of test cases won't occur (Test case 3 tells this) but i was confused for half hours related to this.

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

                You need to realize that often in CP you don't have to solve given tasks for all possible inputs, you only need to pass the tests that will be given to your program. The test case is not formally wrong (it satisfies all constraints in the statement), there even exists a unique correct output for it (the string D that was generated on the server). You just have no way of figuring what D was based on that particular test input.

                In fact, every valid string D could be an answer for every test case. It could happen with non-zero probability that the first generated digit was nearly always nine, yet model solution would guess that corresponding letter was one.

                But again, your goal is to pass the test cases fed to your program: if you (in any task, not just this one) send a solution that will produce output that's judged as correct with probability close to one, you effectively solved the problem (in CF there are hacks as well that one has to care about though).

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

        Calculate the probability of that happening. It will be tending to 0.

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

        Yes. You may get 664 heads in a row when tossing a coin.

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

I did following on B: character for $$$0$$$ is easy to find, after this considered all the permutations of the letters ($$$9!$$$ permutations) and found the mean of all the numbers represented by such a mapping, the one which is closest to $$$\frac{10^u}{4}$$$ is the answer. But got WA on Test 3. Why is it wrong?

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

    Maybe overflow when you calculate the mean. I think it can happen that the sum of all numbers with an incorrect digit map can exceed 2^64 (I've tried the same solution at first, but it was to slow... Ho did you implement permutations? I've used next_permutation from STL)

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

      I took care of overflow, and verified the same there wasn't any overflow. The overall complexity of my code was $$$O(9! \cdot 9)$$$ And yes I used next_permutation.

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

    I tried testing it locally, even with number of queries upto $$$10^6$$$ the probability of this working is only $$$90\%$$$

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

Does anyone have an idea of the average increase in ranking for a person who is ranked approximately 1500 after they review the round and disqualify cheaters and such? I am currently ranked 1514 and I want to sleep at night with an approximation of my chances of being bumped over the edge!

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

I got WA on test 2 in problem B. Changed unsigned int x to long long x and got AC. The only thing I do with variable x is read it from the input. AFAIK overflow with unsigned int in is not UB. Has anyone an idea what is the problem?

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

    You are reading a number from the input that has the length bigger then the accepted length of the maximum value of a unsigned int. I suppose that the reading truncates and some part is left over and this messes up the rest of your reading. I am not sure what the name of this behaviour is, but I dont think it is overflow.

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

      Yea, I tried with small example and this is probably the reason. You can't read arbitrarily big number from the input and compress it to uint. It will mess up memory. Thanks

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

      This is exactly the reason, why my solution failed Tests 2 & 3 of Problem B.

      No wonder Google got rid of their motto 'Don't be evil!'...

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

Failed this round because I read Q in problem B into int, as in subtask 3 it is always -1. Found out the issue after contest ended :(

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

My solution for B, however, it fails on Test 3 if someone can provide a countercase.

For each test case, I go through all the queries and get the set of distinct alphabets that occurred. Now for a server, I require 10 distinct alphabets if I somehow have less than 10 I add up some characters from my side. Now I go through each permutation of this set and check if it is a valid digit string or not if yes then output it as the answer.

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

Posting this here because there was a question based on this today
I read uniformly randomly selected and the next thought that comes to my mind is I won't be able to solve this.
It would be really helpful if someone can provide some resource or anything on how to approach these questions.

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

    High level approach: solve it the same as any other problem, except that when you want to discard any idea because it is not going to solve some of the tests, you should first think about what are the properties of the tests that break your idea, and how likely are they to be generated randomly.

    You may look around and find some problems of this kind for practice, so that you'll learn the most common observations about random tests (e.g. "randomly generated permutation will have relatively short LIS" or "randomly generated tree will have relatively small depth").

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

      Okay, I'll do that. Thank you.

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

      By "randomly generated permutation will have relatively short LIS", did you mean, that if we generate a large number of completely random sequences, the frequency of LIS = 1 will be maximum? As this sounds weird to me.

      Edit: Please ignore this comment, I got your point. I was thinking something strange. Sorry.

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

My solution for B failed only in test case 3. I made a function for each test case separately. For testcase 3 function is solve3. Here is link to my solution. Appreciate any help.

Update: Got it why my answer is wrong.

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

Can someone explain the solution for B ?

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

    TLDR: If all is really random the frequency of first digit being 1 is bigger than first digit being 2 which is bigger than first digit being 3 ... first digit being 0 has probability of 0 on the other hand.

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

ооо хабиб !!!! когда бой с магкрекором ?

eng edit: ooo habib !!!! whene fight with magcrecor ?

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

Any solution for the A? I don't understand why I got WA

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

    My solution for the first problem was as the following:

    Keep track of the xy coordinates of Peppurr's after each move. If the Manhattan distance between the xy coordinates and the origin became less than or equal to the move count then at this moment they will meet. If the distance is always greater than the move count then it's impossible.

    For example if we considered the first sample case:

    4 4 SSSS

    After the first move the distance = |4| + |3| = 7 > 1 (can't meet)

    After the second move the distance = |4| + |2| = 6 > 2 (can't meet)

    After the third move the distance = |4| + |1| = 5 > 3 (can't meet)

    After the fourth move the distance = |4| + |0| = 4 = 4 (can meet)

    Then the solution equals to 4

    Here is my code for this problem. This is the only problem I could solve completely correctly in this round :"D

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

I am trying to solve B for Test Set 2 but it failed with WA however it passes Test Set 1. It seems I do the same what is written in the analysis but it keeps failing. Can anybody help me to find mistakes in my solution?

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

    M and many other things need to be long long

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

      That was the problem! It works now. Thanks a lot!

      I mistakenly thought that the upper bound for M is 2^U but not 10^U. A silly mistake :(

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

Can anyone explain Problem C, (Oversized Pancakes). If you could attach the source code,it would be great.