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

Автор maroonrk, история, 8 месяцев назад, По-английски

We will hold AtCoder Regular Contest 174.

The point values will be 300-300-500-500-700-900.

We are looking forward to your participation!

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

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

As a writer, my shittest mistake is got negative color change at ARC173, last week. Anyway, GLHF!

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

Wow! 300-300-500-500?

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

Excited!

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

is the difficulty of 500 points problem same in ABC and ARC?

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

That math problem is too hard. Solved it too slowly. I'm losing a lot rating.

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

Today i found out that "1e18" is not equal to 1000000000000000000, it cost me a WA penalty.

Submissions — WA AC , can anybody tell why this happens?

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

    1e18 is equal to $$$10^{18}$$$ if you type cast it to long long.

    The problem is that comparing the equality of long long n and 1e18 automatically converts n to double and thus, its value gets rounded.

    For reference, if you run

    #include <iostream>
    int main() {
        std::cout << (1000000000000000001 == 1e18) << '\n';
        std::cout << (1000000000000000001 == (long long) 1e18) << '\n';
    }
    

    your output will be

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

    "Today i found out that "1e18" is not equal to 1000000000000000000".

    that's not true, I think the way why you probably get WA is something like this:

    #include <bits/stdc++.h>
    int main() {
        std::cout << (999999999999999999 == 1e18); // true
        return 0;
    }
    

    you can read about it here (Precision limitations on integer values)

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

    In fact, 1e18 is a float or a double, so there may be a precision problem. You can use const ll inf=1000000000000000000 to avoid typing 18 zeros in the main body of your program.

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

      const ll inf = 1e18 works, as 1e18 is exactly $$$10^{18}$$$. You probably shouldn't use const ll inf = 1e18 + 1 or similar as that may cause rounding errors. ll(1e18) + 1 works, though.

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

      This is part of my code of another problem: (the problem is CSP-S 2022 T2; link to Luogu)

      long long ans=flag?ask(l1,r1,l2,r2):1e18;
      

      Because 1e18 is not a long long, the ask(l1,r1,l2,r2) is firstly transformed into a float or double before storing into ans, so there's a precision problem. I got WA 0pts on this problem :(

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

    Thanks to all of you for the clarification.

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

    Usually double is precise up to around $$$9 \times 10^{16}$$$ only

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

First time solving problem D in ARC. Thanks for the contest!

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

I hope people stop proposing problems like C to online programming contests :(

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

Why not give a stronger sample for F? It was really a pain debugging the 300-line code with bold eyes :(

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

C is like the coupon collector's problem but I have no idea :(

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

    I didn't solve like the editorial, instead I used dp. Let $$$dp_{i,j,k}$$$, be the expected number of coins player $$$k$$$ will pay if it is player $$$j$$$'s turn and $$$i$$$ values have already appeared. Notice that dp is symmetric, so it is enough to calculate $$$dp_{i,1,1}$$$ and $$$dp_{i,0,1}$$$ and we can derive the other two values from these.

    Trivial case is that all $$$n$$$ values have already appeared, so dp value in those cases is $$$0$$$. Now for the transitions there's really two key steps:

    $$$dp_{x,1,1}=\frac{x}{n}(1+dp_{x,0,1})+\frac{n-x}{n}dp_{x+1,0,1}$$$

    $$$dp_{x,0,1}=\frac{x}{n}dp_{x,1,1}+\frac{n-x}{n}dp_{x+1,1,1}$$$

    If you insert the second formula in the first one you will get dp transition for $$$x$$$ which is dependent on $$$x+1$$$.

    Upd: Great that I am getting downvoted for correct solution.

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

      Interesting, thanks for sharing your solution! I didn't think of DP but tried to solve C in a pure math way during the contest.

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

in problem C,

the fine paid amount could tend to infinity right, so how can one find the expected fine paid in that case ?

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

    Look up geometric distribution and infinite geometric series. The binary tree representation of geometric distribution really helped me, I'll include the image.

    If you've seen n out of N integers, there is p = n / N probability of seeing repeat, and 1 — p probability to see new integer. In the binary tree, if you continue to see repeats you have to follow down the left side of the tree. and by x spin, you have p^x probability to not see a new integer. And since 0 < p < 1, it gets really really small.

    In fact you have p + p^2 + p^3, because you could not see another integer in 1 spin or 2 spins or 3 spins and so on following OR rule of probability. It becomes related to infinite geometric series, this series in fact, which does converge to a value.

    Basically the probability of continually not getting another distinct integer gets smaller and smaller, it approaches 0 is how I think of it. So if you have 4 distinct integers, there is almost 0 probability that you don't get to 5 distinct integer within some number of spins, each spin you don't get it becomes less and less probable.

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

Can someone tell why in problem B greedy is the only solution?

I tried Binary Search but it failed

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

The difficulty of the ARC174 was disappointing, at least for me.

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

    I totally agree as there are $$$201$$$ participants who solved $$$5$$$ problems.

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

It was very enjoyable to stare at problem C for 1:30 hours and have no idea, what to do with it.

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

    Btw, I am surprized by number of solutions of problem C. It looks for me much harder, than problem C from previous round. I guess, it is because it requires some special knowledge, not much related to CP.

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

      Yeah, it's too specific-knowledge requiring problem :(

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

        what? gp summation is too specific knowledge now?

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

          Is it something common now?

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

            It is taught in our schools atleast yes, and it is quite common in programming contests too....im surprised this is the first time you came across it.

            Further, it is not hard to come up with. It is very reasonable sirs

            Suppose we had to find S = 1 + p + p^2 + .....
            pS = p + p^2 + .....
            (1 — p)S = 1.
            S = 1 / (1 — p)

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

    Question about editorial of problem C.

    "The expected value of the fine increase for the player who is playing is expressed as $$$p + p^3 + p^5 + \dots$$$."

    It is not mentioned, how to get it. I could get it, but in several not trivial steps. How to get it more easily?

    There is a formula $$$p + 2 \cdot p^2 + 3 \cdot p^3 + \dots$$$ = $$$\frac{p}{(1-p)^2}$$$. How I got it: I knew that for geometric distribution the expected value is $$$\frac{1}{p}$$$, but at the same time it is $$$1 + 0 \cdot P(0) + 1 \cdot P(1) + 2 \cdot P(2) + 3 \cdot P(3) + \dots = 1 + 0 \cdot p + 1 \cdot (1 - p)p + 2 \cdot (1 - p)^2p + 3 \cdot (1 - p)^3p + \dots = 1 + p((1 - p) + 2 \cdot (1 - p)^2 + 3 \cdot (1 - p)^3 + \dots) = \frac{1}{p}$$$. Then substitute $$$p := 1 - p$$$ and get $$$1 + (1 - p)(p + 2 \cdot p^2 + 3 \cdot p^3 \dots) = \frac{1}{1 - p}$$$. From it we get the formula.

    Now, the probability, that fine increase is $$$0$$$ is equal to $$$(1 - p)$$$ — the first player immediately gets new number. The probability, that fine increase is $$$1$$$ is equal to $$$p(1 - p) + p^2(1 - p)$$$ — either the first player pays, and the second player gets new number, or the first player pays, the second player pays, and the first player gets new number.

    Add these expessions and simplify: $$$(1 - p)(1 \cdot (p - p^2) + 2 \cdot (p^3 - p^4) + 3 \cdot (p^5 - p^6) \dots) = (1 - p)((p^2 + 2p^4 + 3p^6 + \dots) + \frac{1}{p} \cdot (p^2 + 2p^4 + 3p^6 + \dots)) = (1 - p)(\frac{p^2}{(1 - p^2)^2} + \frac{p}{(1 - p^2)^2}) = \frac{p}{1 - p^2}$$$ as in editorial, but not magically.

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

      The probability that the game goes on for another x turns without getting a new element is p^x.

      The first player pays the fine on odd turns, so p + p^3 + ....

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

      Google "Tail sum formula for expectation" — $$$E(X) = \sum_{i=0}^\infty P(X > i)$$$.

      You can also find the expectation via a recurrence. Say that the last person to get the distinct number was the first player. $$$X$$$ is the amount of fines paid by the first player. Then,

      $$$ E(X) = p^2 (1 + E(X)) $$$

      Basically, the second player pays a fine, then the first player pays the fine, and you're back to the "starting position". For any other possibility, the contribution to the number of fines would be zero. You can do the same thing for other cases similiarly.

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

Despite I find C very easy, I think is more harder than D

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

I was a bit disappointed today. Of course I didn't perform well. But usually when doing ARC you always get to do some cool observations or some out-of-the-box thinking. Today I found most problems to be quite "inside-the-box". Pretty standard, but not trivial to implement. Also the difficulty was not up to par, as now there's a giant tie with $$$5$$$ problems solved.

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

Couldn't solve A :(

Solved B and D though

For C: Can someone give suggestions on how to solve questions on probabilities like C one? Are these purely mathematical questions or are there some other (cooler) ways to approach these problems?

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

    Actually you can also solve C in DP instead of pure math. Here is my code, and the only mathematical part is calculating something like $$$x+x^2+x^3+\dots$$$.

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

      Hmmm I see... a similar question involving probabilities and DP had come in my previous year's ICPC preliminary contest too... ig I need to practise these more often because they just seem so out of my capability rn.

      Thank you for the hint and code :)

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

    For problem A. There are two cases:

    Case 1. $$$C > 0$$$. We need to find the segment with maximum sum and apply the operation on it. If sum on segment is less than $$$0$$$, we don't need to do operation.

    Case 2. $$$C \le 0$$$. We need to find the segment with minimum sum and apply the operation on it. If sum on segment is greater than $$$0$$$, we don't need to do operation.

    How to find segment with maximum sum (with minimum the same way). Calculate prefix sums $$$p[i] = a[0] + a[1] + \dots + a[i - 1]$$$. The sum on segment is $$$p[r + 1] - p[l]$$$. Then we need to find maximum $$$p[r + 1] - p[l]$$$ for $$$r \ge l$$$. We can do this:

    left = p[0]
    sum = -inf
    for i = 1 .. n:
        res = max(res, p[i] - left)
        left = min(left, p[i])
    
    • »
      »
      »
      8 месяцев назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      I ran kadanes algo to find subarray with max sum and sub array with min sum

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

      Another approach:

      def solve(a, c):
        s0, s1, s2 = 0, 0, 0
        for x in a:
          s0, s1, s2 = s0 + x, max(s0, s1) + x * c, max(s1, s2) + x
      
        return max(s0, s1, s2)
      
    • »
      »
      »
      8 месяцев назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Yupp I realised the correct approach immediately once i started fresh after the contest, and it is same as your approach. Kinda scary how I fumble easy questions.

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

A — Math

B — Math

C — Math

D — Math

WTF, mathCoder.


UPD This round is downvoted, it seems that everyone has the same idea with me

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

C is a cute problem, thanks

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

How to solve B?

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

Problem A Very close to a problem I solved on CodeForces

1155D - Beautiful Array

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

Is solving 1900 rating problem in atcoder is harder or solving 2200 rating problem in codeforces is harder, can anyone please clarify?

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

Binary Search solution to problem B: Submission $$$\newline$$$ Let the original mean be $$$\frac{num}{den}$$$ and the price of $$$4\star$$$ and $$$5\star$$$ review be $$$a$$$ and $$$b$$$ respectively. $$$\newline$$$ $$$\mathbf C\mathbf a\mathbf s\mathbf e1:$$$ If the $$$mean$$$ $$$\ge 3$$$ or $$$a=0$$$ or $$$b=0$$$ then answer is $$$0$$$. $$$\newline$$$ Using a $$$4\star$$$ or a $$$5\star$$$ review is always better to increase the mean. Suppose we use $$$k$$$ reviews out of which $$$x$$$ are $$$4\star$$$ and $$$k - x$$$ are $$$5\star$$$. If the minimum price is $$$m$$$ then we have the following inequalities. $$$\newline$$$ $$$\mathbf I\mathbf n\mathbf e\mathbf q\mathbf u\mathbf a\mathbf l\mathbf i\mathbf t\mathbf y0:$$$ $$$k \geq 1$$$ $$$\newline$$$ $$$\mathbf I\mathbf n\mathbf e\mathbf q\mathbf u\mathbf a\mathbf l\mathbf i\mathbf t\mathbf y1:$$$ $$$0 \leq x \leq k$$$ $$$\newline$$$ $$$\frac{num+4x+5(k - x)}{den + k}\ge 3$$$ $$$\newline$$$ Let $$$c= 3den - num$$$ $$$\newline$$$ $$$\mathbf I\mathbf n\mathbf e\mathbf q\mathbf u\mathbf a\mathbf l\mathbf i\mathbf t\mathbf y2:$$$ $$$x\le 2k - c$$$ $$$\newline$$$ $$$ax + b(k - x) \leq m$$$ $$$\newline$$$ $$$\mathbf C\mathbf a\mathbf s\mathbf e2:$$$ If $$${\mathrm{b}} \leq {\mathrm{a}}$$$ then its always better to use a $$$5\star$$$ review so we get $$$\frac{{\mathrm{c}}}{2}{\mathrm{b}} \leq {\mathrm{m}}$$$ $$$\newline$$$ $$$\mathbf C\mathbf a\mathbf s\mathbf e3:$$$ If $$${\mathrm{b}} \gt {\mathrm{a}}$$$ $$$\newline$$$ $$$\mathbf I\mathbf n\mathbf e\mathbf q\mathbf u\mathbf a\mathbf l\mathbf i\mathbf t\mathbf y3:$$$ $$$x \geq \frac{m - bk}{a - b}$$$ $$$\newline$$$ On solving $$${\mathrm{Inequality}}2$$$ with $$${\mathrm{Inequality}}1$$$ we get $$$\newline$$$ $$${\mathrm{k}} \geq \frac{{\mathrm{c}}}{2}$$$ $$$\newline$$$ On solving $$${\mathrm{Inequality}}3$$$ with $$${\mathrm{Inequality}}1$$$ we get $$$\newline$$$ $$${\mathrm{k}} \leq \frac{{\mathrm{m}}}{{\mathrm{a}}}$$$ $$$\newline$$$ On solving $$${\mathrm{Inequality}}2$$$ with $$${\mathrm{Inequality}}3$$$, we get $$$\newline$$$ $$${\mathrm{m}} + {\mathrm{c}}({\mathrm{a}} - {\mathrm{b}}) \geq (2{\mathrm{a}} - {\mathrm{b}}){\mathrm{k}}$$$ $$$\newline$$$ $$$\mathbf C\mathbf a\mathbf s\mathbf e3.1:2{\mathrm{a}} - {\mathrm{b}} \gt 0$$$ $$$\newline$$$ $$${\mathrm{k}} \leq \frac{{\mathrm{m}} + {\mathrm{c}}({\mathrm{a}} - {\mathrm{b}})}{2{\mathrm{a}} - {\mathrm{b}}}$$$ $$$\newline$$$ Combining all the inequalities we get $$${\mathrm{\max }}(\frac{{\mathrm{c}}}{2},1) \leq {\mathrm{k}} \leq {\mathrm{\min }}(\frac{{\mathrm{m}} + {\mathrm{c}}({\mathrm{a}} - {\mathrm{b}})}{2{\mathrm{a}} - {\mathrm{b}}},\frac{{\mathrm{m}}}{{\mathrm{a}}})$$$ $$$\newline$$$ $$$\mathbf C\mathbf a\mathbf s\mathbf e3.2:2{\mathrm{a}} - {\mathrm{b}} \lt 0$$$ $$$\newline$$$ $$${\mathrm{k}} \geq \frac{{\mathrm{m}} + {\mathrm{c}}({\mathrm{a}} - {\mathrm{b}})}{2{\mathrm{a}} - {\mathrm{b}}}$$$ $$$\newline$$$ Combining all the inequalities we get $$${\mathrm{\max }}(\frac{{\mathrm{m}} + {\mathrm{c}}({\mathrm{a}} - {\mathrm{b}})}{2{\mathrm{a}} - {\mathrm{b}}},\frac{{\mathrm{c}}}{2},1) \leq {\mathrm{k}} \leq \frac{{\mathrm{m}}}{{\mathrm{a}}}$$$ $$$\newline$$$ $$$\mathbf C\mathbf a\mathbf s\mathbf e3.3:2{\mathrm{a}} - {\mathrm{b}} = 0$$$ $$$\newline$$$ Combining all the inequalities we get $$${\mathrm{\max }}(\frac{{\mathrm{c}}}{2},1) \leq {\mathrm{k}} \leq \frac{{\mathrm{m}}}{{\mathrm{a}}}$$$ and $$${\mathrm{m}} \geq - {\mathrm{c}}({\mathrm{a}} - {\mathrm{b}})$$$ $$$\newline$$$

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

Very enjoyable problems.

For problem E I am wondering what is the way to understand why you take (c — 1) * nPk * k / n term. In specific, why is k / n factor needed. I think it is because you have k / n probability of picking the element out of k available slots and n elements. So I generalized this to this principle. The count of permutations in which element i appears within when you are choosing k from n is nPk * (k / n). But what is reasoning for this?