chrome's blog

By chrome, history, 9 years ago, translation, In English

Hi there!

Tomorrow, after Codeforces Round #322 at 14:00 MSK will be held Topcoder SRM 669.

Let's discuss problems after contest!

  • Vote: I like it
  • +153
  • Vote: I do not like it

| Write comment?
»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Does anybody have problems launching arena?

  • »
    »
    9 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I have just launched it and registered with no problems.

»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Funnily enough, you show up in the division summary, so I guess you were registered after all.

    • »
      »
      »
      9 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      So the Java arena was the one bugged... Oh well :(

»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    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 years ago, # ^ |
        Vote: I like it -8 Vote: I do not like it

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

  • »
    »
    9 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    9 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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 years ago, # ^ |
    Rev. 5   Vote: I like it 0 Vote: I do not like it

    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 years ago, # |
  Vote: I like it -9 Vote: I do not like it

going to be unrated because of d1 hard?

  • »
    »
    9 years ago, # ^ |
      Vote: I like it +4 Vote: I do not like it

    Doesn't look like it. My rating changed.

    • »
      »
      »
      9 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      It is really strange decision.

      • »
        »
        »
        »
        9 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Strange? To rate it?

        • »
          »
          »
          »
          »
          9 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          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 years ago, # ^ |
            Rev. 2   Vote: I like it +15 Vote: I do not like it

            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 years ago, # ^ |
                Vote: I like it 0 Vote: I do not like it

              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 years ago, # ^ |
                Rev. 2   Vote: I like it 0 Vote: I do not like it

                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 years ago, # ^ |
                  Vote: I like it +1 Vote: I do not like it

                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 years ago, # ^ |
                    Vote: I like it +8 Vote: I do not like it

                  Ok, you right, code is not the same, so all is ok.

          • »
            »
            »
            »
            »
            »
            9 years ago, # ^ |
              Vote: I like it +29 Vote: I do not like it

            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 years ago, # ^ |
              Vote: I like it +5 Vote: I do not like it

            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 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    9 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

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

    • »
      »
      »
      9 years ago, # ^ |
      Rev. 2   Vote: I like it +2 Vote: I do not like it

      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 years ago, # ^ |
          Vote: I like it +9 Vote: I do not like it

        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 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

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

        • »
          »
          »
          »
          »
          9 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          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 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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 years ago, # |
  Vote: I like it +1 Vote: I do not like it

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 years ago, # ^ |
      Vote: I like it +11 Vote: I do not like it

    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 years ago, # ^ |
    Rev. 7   Vote: I like it +27 Vote: I do not like it

    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 years ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      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 years ago, # ^ |
        Rev. 3   Vote: I like it +3 Vote: I do not like it

        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 years ago, # ^ |
      Vote: I like it +9 Vote: I do not like it

    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 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    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 years ago, # |
  Vote: I like it +11 Vote: I do not like it
»
9 years ago, # |
  Vote: I like it +6 Vote: I do not like it
»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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 years ago, # ^ |
    Rev. 3   Vote: I like it +9 Vote: I do not like it

    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 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

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

      Could you kindly shortly explain solution of Div1 Hard?

      • »
        »
        »
        »
        9 years ago, # ^ |
        Rev. 2   Vote: I like it +12 Vote: I do not like it

        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 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          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 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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 years ago, # |
  Vote: I like it +27 Vote: I do not like it

Finally you made it, chrome. Congrats!