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

Автор chrome, история, 9 лет назад, По-русски

Всем привет!

Завтра, после Codeforces Round #322 в 14:00 MSK состоится Topcoder SRM 669.

Предлагаю обсудить задачи после контеста!

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

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

Спасибо за предупреждение!)

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

Does anybody have problems launching arena?

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

The only reason I use web arena is to register on mobile, today it told me "you are successfully registered" and I wasn't u.u

Why not open registration 12 hours before the round, TC?

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

What was the logic behind Div1 250? I noticed the pattern that you should divide S into almost equal blocks, but how can it be explained?

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

    Suppose that at the end of the day we have pieces a1, a2, ..., ak Now the total number of muppets is One can check that if ai ≥ aj + 2 then by replacing ai, aj by ai - 1, aj + 1 we will increase f(a)

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

      Got it. I thought of a problem from a completely different side and didn't notice it. Thanks.

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

    Consider a slime of size S as a collection of S "blocks". Your total score is the number of unordered pairs of blocks which belong to different slimes, regardless of the order of divisions you used to produce those slimes. If two slimes differ in size by at least 2, you can transfer 1 block from the larger one to the smaller one to increase your score, so it's always optimal to have the sizes almost equal.

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

    Overall profit is . Given that it is easy exercise to notice that it is best to cut to almost equal sizes.

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

    Informally: If at some point you have pieces of size (A1,...,Ak), to "assemble" them back into a whole slime would require sum of all pairwise products Ai*Aj, regardless of the order. Therefore, the optimum division into K parts is such that it maximizes the product. And that would be division into equal parts.

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

    Another proof for the division into equal pieces being optimal is if you have n = a+b, you need to maximize f(n) = a*(n-a) where 1<=a<=n. Differentiating that function wrt a and equating it to 0 to find maxima, you get d(an-a*a)/da = 0. You can apply that to the pair of variables in each term in your final expression to maximize the product of that term.

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

going to be unrated because of d1 hard?

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

    Doesn't look like it. My rating changed.

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

      It is really strange decision.

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

        Strange? To rate it?

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

          Yes it is strage, because somebody could take huge advantage. May be they asked all people who solved it today and none of them solved this problem before.

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

            Even if somebody knew it beforehand — how much did it affect whole contest considering that hundreds of people competed? It is a really often case that some problem appeared somewhere else (if I remember well — take a look at contests created by Bayan (not Thanks round) — almost half of problems there appeared somewhere earlier, bad luck) and I don't see many unrated contests because of that. We have to deal with fact that number of reasonable problems is finite and that birthday paradox is in fact true.

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

              AT first everybody should try to avoid using well-known problems in contest. At second it is a big difference between problem "similar to some problem which was years ago" and completely the same problem, which was used on the same judge and probability that somebody knows it (and even has code for this problem) is very high.

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

                I think that it didn't happen to me that I copied code and didn't change anything, but it happened few times that I copied code and slightly adjusted it, e.g. 5 lines out of 100 (once even one line in a really tough problem), which is still not what you want. Such unfortunate things happen, there is no way to prevent this in general and unrating contest for hundreds of people would be definitely too forward.

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

                Btw, lol, don't know if you read this "exactly the same problem" http://community.topcoder.com/stat?c=problem_statement&pm=11155&rd=14552, probably not — if you did then you wouldn't be talking that they are exactly the same :P.

                Indeed the problems are very similar, but you can't simply copy code.

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

            Well, as someone who participated in both competitions and solved this problem in both competitions — I had not remembered that problem during the contest and my solution is completely different from the one I used 4 years ago. Petr even hadn't solved it this time despite solving it 4 years ago

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

            I remembered this problem and wrote the same wrong solution as in the previous srm.) It didn't pass pretests, and I finally got what I'd done.

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

      Good then, because my 250 survived three challenges, including one from Petr xD

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

    I didn't take part. What is the story about d1 hard?

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

      It's a copy of a d1 hard from a previous srm here. (They have some slight differences, though the way to solve is basically the same).

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

        Not exactly true. My solution specifically use condition that ratio of 2 consecutive coin values is at most 1000. As far as I know author solution uses this as well. So you cannot solve problem from 4 years ago using my current solution

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

          Oh whoops, I had made the same assumption in my solution as well. Thanks for pointing this out.

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

          I see the only problem with my solution: I count dp[k][sum] -- if we have k different types of ones, what's the number of ways to take exactly sum ones with less than m of each type. As you said m in the previous problem could be very large, so I need to count this value for only one pair (k, sum). Is there any formula? Or maybe I should think from different direction?

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

Haha, 7 successful hacks (and 1 not), what a hacking spree for me :v. It is even more funny for me, because hacking anybody is a really rare case for me, recently I few times omitted hacking phase on purpose, because it happened to me few times that only thing I did was to unsuccessfully challenge somebody :P.

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

Could someone tell me what is the error in the greedy approach of taking S and breaking it into two almost equal halves, keep them in a set and then repeat this process using the largest element present in the set?

Also, How to solve Div 1 B?

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

    Better question — could you tell me the proof of that solution? Solution is incorrect as long as you don't have a proof, not correct as long as you don't have a counterexample.

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

    Div1 B

    Let's dp(n, x) = answer for the problem, if n is number of vertices of a graph, x is maximum cost of edge that this graph can have.

    Let's associate cost x to edge of vertices i and i + 1 on a line. Every edge (u, v) where u <= i and v > i cannot have cost smaller than x, because we want (i, i + 1) to be in MST, thus they can contain costs between x..L

    so dp(n,x) = dp(n, x-1) + sum dp[i][x-1]*dp[n-i][x] * (L-x+1)^(i*(n-i)-1)

    UPD.
    dp[i][x-1] to avoid counting one MST more than once.
    Answer for the problem is dp(N, L) * fac(n) / 2

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

      why do we have dp[i][x-1]*dp[n-i][x] but not a dp[i][X]*dp[n-i][x] ? I mean why we do not have dp[i][x] instead of dp[i][x-1] in your formula?

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

        It is written in the bottom of my explanation. But I think it is hardly visible.

        Shortly, you don't want to count the same MST twice, so the FIRST edge with associate cost x will be (i, i + 1).

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

    Here is the test for you.

    10 33.

    You can reach 33 in two moves by dividing 10 into 7 and 3, and then 7 into 3 and 4 again. However, your greedy gives 10=5+5=5+2+3 with 31 points.

    Trick is — you are interested in having almost equal parts (3-3-4 in this case) at the end of your process, not as a results of every single move.

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

Hi guys,

Could someone explain, what is mathematical proof of SRM669 Div2 500's problem's solution, so that it does not matter what numbers you would take in array, the result will be the same?

Thank you!

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

    Answer is always sum of the product of pairs. So it doesn't matter in which order you select two nos. Let say elements of array is a,b,c and d then ans is ab+ac+ad+bc+bd+cd. Proof directly comes from the distributive property of addition.

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

what about Div2 Hard, I tried to right dp solution with the index of the edge and number of ones and twos as my state 120 X 120 X 120 but I found that its counting non-line MSTs too.

What is the right approach ??

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

    Note, this is a solution to the harder Div1 version (an exponential approach will probably work for the div2 version, though I don't see what it is immediately now).

    First, let's rephrase the problem. Instead of generating graphs, then counting line MSTs, let's generate line MSTs and count graphs.

    A line MST looks like a permutation of the n nodes, where adjacent nodes are neighbors. There are a total of n!/2 ways to arrange the nodes (there are n! ways, but we double counted lines because it doesn't matter if we're going forward or backwards on the line).

    So now, WLOG, we can label our line MST so it looks like 1-2-3-...-n (we'll multiply our answer by n!/2 afterwards).

    Let dp[i][j] denote the number of graphs with i nodes and a line MSTs on 1-2-...-i, where the maximum edge has a value of at most j.

    First, if no edges have value j, then the number of ways is just dp[i][j-1]. Otherwise, we can enumerate through all positions k where the first edge with value j appears. After determining this edge k, there are a total of dp[k][j-1] * dp[i-k][j] * exp(L — j + 1, k * (i-k) — 1) ways (this will be explained a bit more below). We can sum over all k to get our answer. Thus, this dp takes O(n^2*L) time.

    Now, about the product I'll explain it as follows:

    • After we choose that the k-th edge has value j, all edges crossing the cut from {1,2,..,k} and {k+1,...,i} must have value at least j. Thus, there are a total of k*(i-k)-1 cross edges (not including the edge from k to k+1), and each edge has L-j+1 choices. This gives us the exp(L-j+1,k*(i-k)-1) term. Note that this follows from the cut property of an MST (any edge with minimum cost crossing a cut is included in some MST).

    • Since we said that k is the first edge with value j, all edges in {1,2,..,k} has value at most value j-1, so this gives the term dp[k][j-1]

    • Lastly, the remaining cut {k+1,...i} has a total of dp[i-k][j] (we can still use edges of at length at most j, and we relabel nodes so they're now {1,...,i-k} instead).

    There's probably a much simpler method for div2 hard, since constraints are so much smaller.

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

      Thanks for a such explanation! I finally understood the solution.

      Could you kindly shortly explain solution of Div1 Hard?

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

        Sure. My solution is a bit complicated, so there is probably a way to simplify it. I'll present a very summarized version here. The key ideas for this problem are matrix exponentiation, so I hope you are familiar with that topic.

        First, let's assume for simplicity that X is a power of M (i.e. X = M^k for some k). Now, in order to count distinct ways to sum up to X, we'll first order our summands in decreasing order.

        Now, to make X, we can either just have the term M^k, or we can have M blocks that sum up to M^(k-1). Now, these M blocks must be in decreasing order, so we need to know what the first and last element of each blocks are. This suggests a dp approach with three states. That is, let dp[i][j][k] be the number of ways to make M^i where the first term is at most M^j, and the last term is exactly M^k (note each of the dimensions in this dp is at most log_2(10^18), which is about 60).

        We can compute dp[i] almost as dp[i-1]^M. We need to modify dp[i] a bit to accomodate for the fact that we also have M^i that we can use as a summand (dp[i-1] only uses M^0,M^1,..,M^(i-1)).

        Thus, to solve when X is a power of M, you can sum over all entries in the first row of the matrix dp[k].

        To solve for general X, write X in base M. Suppose it's X = a_k * M^k + a_(k-1) * M^(k-1) + ... + a_0 * M^0. Then, the answer is the sum of the first row of all entries in the matrix prod(dp[i]^(a_i)).

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

          Wow, that is very clever :)! However one problem which I had during reading this was understanding "Now, to make X, we can either just have the term M^k, or we can have M blocks that sum up to M^(k-1). Now, these M blocks must be in decreasing order, so we need to know what the first and last element of each blocks are." What you want to claim is that if we put summands in decreasing order then all multiplies of M^(i-1) will appear among prefix sums and it wasn't clear for me neither that you're claiming it and why it is true :P (ok, second one is easy, but not knowing first one caused a confusion).

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

For div1 500,I think the key point is the way to construct the line MST.At last,the answer should multiply n! and because of it's sysmetry we should divide the answer by 2. If I'm wrong,please tell me,thanks. But how to find it's sysmetry quickly?

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

Finally you made it, chrome. Congrats!