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

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

Thanks for the participation! We hope you enjoyed the contest.

Rate the contest!

The solution codes will be added shortly after the system tests are finished. They have been added.

2160A - MEX Partition

Problem Credit: Proof_by_QED

Rate the problem!
Solution
Code (chromate00)

2160B - Distinct Elements

Problem Credit: Proof_by_QED

Rate the problem!
Solution
Code (chromate00)

2160C - Reverse XOR

Problem Credit: Proof_by_QED

Rate the problem!
Solution
Code (chromate00)

2159A - MAD Interactive Problem

Problem Credit: wuhudsm

Rate the problem!
Solution
Code (_istil)

2159B - Rectangles

Problem Credit: chromate00

UPD: I sincerely apologize about the weak pretests of the problem. I have greatly underestimated the runtime and memory usage of the worst solutions, while still wanting to be generous about slower solutions. This has led to weak tests during contest. Deeply sorry about the bad contest experiences affected by this.

Rate the problem!
Solution
Code (chromate00, O(min(n,m)(n+m)) memory)

2159C - Twin Polynomials

Problem Credit: wuhudsm

Rate the problem!
Solution
Code (wuhudsm)

2159D1 - Inverse Minimum Partition (Easy Version), 2159D2 - Inverse Minimum Partition (Hard Version)

Problem Credit: chromate00, wuhudsm; Special Thanks: satyam343

Rate the problem!

This problem's editorial will be divided into parts. You may need to read all of them to understand the full picture.

Part 1
Part 2.1
Part 2.2
Part 2.3
Part 3 (for Hard subtask)
Code (chromate00, Easy Part 2.1)
Code (chromate00, Hard)

2159E - Super-Short-Polynomial-San

Problem Credit: chromate00; Special Thanks: Proof_by_QED, zeemanz

Rate the problem!
Solution
Code (chromate00)

2159F - Grand Finale: Snakes

Problem Credit: wuhudsm

Rate the problem!
Solution
Code (wuhudsm)
Разбор задач Codeforces Round 1058 (Div. 1)
Разбор задач Codeforces Round 1058 (Div. 2)
  • Проголосовать: нравится
  • +68
  • Проголосовать: не нравится

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

first.

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

Please give each problem's credits ;)

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

C was easier than B

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

wow , thanks for superfast editorial..

thanks for cool problems ( I am biased, as I will get good +ve delta )

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

Div1B = Div2E was very similar to a problem that I made in a Korean contest (https://www.acmicpc.net/problem/34058). One of the problemsetters today had participated in that contest and has a record of getting accepted in BOJ.

I don't think this is plagiarism, since the problem situation is slightly different, and we often see coincidences in this field. However, I still think there is a high probability that this problem could be inspired by my problem, or affected by it.

»
6 месяцев назад, скрыть # |
Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

Does anyone have an explanation for why this my Div2E solution got TLE on system tests even though it's practically the same as the editorial solution? 343394700

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

    I have added my apology above the problem editorial. I thought most bad solutions should die due to most random tests (which we have a variety of).

    For why your solution gets TLE; I think it is due to the use of many nested std::vectors. std::vectors are dynamically allocated, so nesting them makes it so that the elements are not contiguous in memory. This leads to very bad constants.

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

      Sadly, even after minimizing nesting and some other optimizations, I'm still getting TLE 343416181, do you have any other suggestions? Regardless, I really loved the contest, thank you for making it!

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

        making it an array of std::vectors doesn't help as they are still dynamically allocated. probably you can look for the way to optimize the space complexity to $$$\mathcal{O}(\min(n,m)(n+m))$$$ and that might help.

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

          I knew changing some of the nested vectors to arrays probably wouldn't do much, I was mainly referring to the changing of my pairs vector to be only doubly nested compared to triply nested (and same with the curr_idx vector). With that being said, I'll give this a shot later, thank you so much for the help!

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

For Div1 D1/Div 2 G1, there's a much easier version of CHT compared to Part 2.3 of the editorial. The trick is to do DP on suffixes rather than prefixes.

Let $$$v_1, v_2, \dots, v_n$$$ be the array, and assume $$$v_1 \lt v_2 \lt \dots \lt v_n$$$ (using observation 1.a).

Let $$$dp(i)$$$ denote the min cost to partition the subarray $$$v[i..n]$$$. Then $$$dp$$$ satisfies the recurrence

$$$\displaystyle dp(i) = \min_{j \gt i} \left(dp(j) + \left\lceil \frac{v_{j-1}}{v_i}\right\rceil\right).$$$

We could already use CHT here, since this is the same as querying for the min y-value (rounded up) at $$$x=\frac{1}{v_i}$$$ over all lines of the form $$$y_j(x) = dp(j) + v_{j-1}x$$$.

But to avoid floats, we can multiply and divide by $$$v_i$$$ to get

$$$ dp(j) + \left\lceil \frac{v_{j-1}}{v_i}\right\rceil = \left\lceil\frac{v_i dp(j) + v_{j-1}}{v_i}\right\rceil. $$$

Then, we can query for the min at $$$x=v_i$$$ over lines of the form $$$y_j(x) = xdp(j) + v_{j-1}$$$, then set $$$dp(i)$$$ to be the result divided by $$$v_i$$$ (rounded up).

343413853

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

    There also exists an O(n log n) solution for D1/G1 that doesn’t use any data structure, and it can easily be optimized to O(n).

    O(n log n)
    O(n)

    UPD: nvm — part 2.2 of the editorial already includes this approach.

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

I ran my solution to 2E (which mle'd on system tests) in gym with higher limits and it takes 3.5/4s and 1400/1024 MB.

I'm not sure if its possible to optimize. :(

My solution idea was to use a bitset which denotes which elements of the frequency array are positive and use find first to find the best area.

Submission: 343415947

Update: I used short instead of int for areas that are small enough and my solution passed.

Submission: 343431788

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

The limits for Div 1 E seem rather tight (all the solutions take over half the time limit, and mine is the only solution that uses under half the memory limit).

I wonder how much time / memory the model solution / testers' solutions used.

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

    The model uses 3296ms and 461MB, where the tester's AC uses 3624ms and 348MB. I believe this meant there was quite some margin in TL to adjust the value of $$$B$$$ and bring the memory usage lower, at the cost of slightly slower solution.

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

I think some users had issues, but an overall good contest and nice questions.

Thank you for organizing!

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

B was really nice, missed C by like 5 minutes, shouldve started on time

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

L testcases for div1B

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

Found some approach for div2F (without fixed elements):

Suppose $$$a_0 = 0$$$.

Then all $$$a_1, \dots, a_n \gt 0$$$. This means that $$$f(x)$$$ has exactly $$$n$$$ terms, while $$$g(x)$$$ has at most $$$n$$$ terms.

For the identity $$$f(x) = g(x)$$$ to hold, it is necessary that all $$$a_i$$$ are distinct and form a permutation of $$${1, 2, \dots, n}$$$.

Any such permutation gives a valid steep polynomial.

Suppose $$$a_0 \gt 0$$$.

Then there exist indices $$$i_1, \dots, i_k$$$ such that:

$$$a_{i_1} = a_{i_2} = \dots = a_{i_k} = 0$$$

$$$i_1 + i_2 + \dots + i_k = a_0$$$

$$$i_1, \dots, i_k \in {1, \dots, n}$$$

The remaining indices $$$j_1, \dots, j_m$$$ will have:

$$$a_{j_1}, \dots, a_{j_m} \gt 0$$$

Then $$$f(x)$$$ has exactly $$$m+1$$$ terms, and $$$g(x)$$$ has at most $$$m+1$$$ terms.

For $$$f(x) = g(x)$$$ to hold, it is necessary that all $$$a_{j_1}, \dots, a_{j_m}$$$ are distinct and form a permutation of the remaining elements in $$${1, \dots, n} \setminus {i_1, \dots, i_k}$$$.

Any such permutation gives a valid steep polynomial.

Is it correct? Can be impemented?

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

    This approach is incorrect.

    Usually, when I guess a conclusion, my first step is to check it against the sample cases for a sanity check.

    Consider this test case from the samples:

    3
    -1 2 3 -1
    

    The answer for it is $$$0$$$, which means that $$${0, 2, 3, 1}$$$ is not a valid solution. However, your logic for the $$$a_0 = 0$$$ case would have considered this valid, since $$${2, 3, 1}$$$ is a permutation of $$${1, 2, 3}$$$.

    In fact, the conditions you've proposed are too weak. The actual constraint is that for any index $$$i$$$ such that $$$i \neq 0 \land a_i \neq 0$$$, the condition $$$a_{a_i} = i$$$ must also be satisfied.

    For more specifics, you can read the editorial to understand this. I won't elaborate further.

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

fast editorial)

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

Can anyone explain Rectangle problem dp part mentioned in the editorial?

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

    DP is unnecessary for this part of the problem. (Assume #rows>#columns) Say we have already computed area[i][l][r], which stores the smallest area rectangle that overlaps row = i, has left end point = l, and has right end point = r. Then the answers for row i can be computed simply by:

    for(int l=0; l < #cols; l++) {
    
        int mn = INF;
    
        for(int r = #cols - 1; r >= l; r--) {
    
            mn = min(mn, area[i][l][r]);
    
            ans[i][r] = min(mn, ans[i][r]);
        }
    }
    
    

    Basically just fix a left endpoint, and iterate over rectangles from most wide to least wide. I think once you understand this it is easy to write a similar dp.

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

My Div1C (Div2F) solution (might really be identical to the editorial's).

First, define $$$f(m) \; (m \ge 0)$$$ as the number of ways of partitioning a set of $$$m$$$ elements into sets of size 1 and 2. This is OEIS A000085, and can be calculated as follows:

$$$\begin{align*} f(0) &= 1, \\ f(1) &= 1, \\ f(m) &= f(m - 1) + (m - 1) \cdot f(m - 2). \end{align*}$$$

Then back to the problem. If we find a valid combination of $$$a_1, a_2, \ldots, a_n$$$, then $$$a_0$$$ is automatically determined, so let's ignore $$$a_0$$$ and pretend that $$$a$$$ is an $$$n$$$ element array $$$[a_1, a_2, \ldots, a_n]$$$. Make sure we exclude the impossible cases and update $$$a$$$ so that, for all $$$i$$$ satisfying $$$a_i \ge 1$$$, $$$a_i = j$$$ and $$$a_j = i$$$ (or $$$a_i = i$$$) holds.

Suppose that there are $$$c$$$ elements of $$$-1$$$ s left in $$$a$$$. Let's ignore the requirement of $$$a_n \ne 0$$$ for now and allow it to become $$$0$$$. Assume we allocate $$$0$$$ to $$$c-k$$$ elements and non-$$$0$$$ values to $$$k$$$ elements out of those $$$-1$$$ s. There are $$$\displaystyle \binom{c}{k}$$$ ways to pick those $$$k$$$ elements. Furthermore, due to the fact that we need to ensure $$$a_i = j$$$ and $$$a_j = i$$$ or $$$a_i = i$$$ for those $$$k$$$ elements, there are $$$f(k)$$$ ways to distribute non-$$$0$$$ values. Therefore, define $$$g(c) \; (c \ge 0)$$$ as follows:

$$$\begin{align*} g(c) = \sum_{k=0}^{c} \binom{c}{k} \cdot f(k). \end{align*}$$$

If $$$a_n \ne -1$$$, there's no possibility that $$$a_n$$$ can be $$$0$$$, so $$$g(c)$$$ is the answer. If $$$a_n = -1$$$, we need to take account of the possibility of $$$a_n$$$ being $$$0$$$. Fortunately, it's not too hard to do that: there are exactly $$$g(c - 1)$$$ ways of possible arrangements such that $$$a_n = 0$$$, so the answer is $$$g(c) - g(c - 1)$$$.

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

    To get rid of binomial coefficients you can change the formula of $$$f$$$ to this:

    $$$f(m) = 2f(m - 1) + (m - 1) \cdot f(m - 2)$$$

    In a combinatorical sense this $$$2$$$ means that we either pair $$$a_i$$$ with itself (set $$$a_i = i$$$) or pair with 0 (set $$$a_i = 0$$$). The answer is $$$f(c) - f(c - 1)$$$

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

    Nice _Kee . how did you get — what to search on OEIS ?

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

      After I found out the requirement was $$$a_i = j, a_j = i$$$ or $$$a_i = i$$$ if $$$a_i \gt 0$$$, I tried to manually count the combinations of positive values of length $$$k$$$, for small $$$k$$$.

      • $$$k = 1$$$. Obviously there is $$$1$$$ way.
      • $$$k = 2$$$. $$$2$$$ ways, with or without swap.
      • $$$k = 3$$$. $$$1$$$ way without swap, $$$\displaystyle \binom{3}{2} = 3$$$ ways with swap; $$$4$$$ in total.
      • $$$k = 4$$$. $$$1$$$ way without swap, $$$\displaystyle \binom{4}{2} = 6$$$ ways with one swap, $$$\displaystyle \binom{4}{2} \binom{2}{2} \cdot \frac{1}{2} = 3$$$ ways with two swaps; $$$10$$$ in total.
      • $$$k = 5$$$. Similarly $$$26$$$ ways in total.

      Then I went to OEIS and looked up $$$[1, 2, 4, 10, 26]$$$ and found this sequence. It indeed looked the right one according to the EXAMPLES section. So I used recursive formula in that page.

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

I don't know what to think about the F problem editorial. I have submitted a solution after the contest (I was close during the contest but lacked time) and i have a different equation: dp[i] = 2*dp[i-1] + (i-2)*dp[i-2]. It's not easy to say if the editorial is wrong since "After that, the problem reduces to the easy version." makes it hard to tell if they reduce it in a different way or the equation is wrong. I have (i-2) instead of (i-1) since we don't want to "swap" i-th element with 0.

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

in problem D1, part2.2 how to prove that cost(P) <= x? I am really bad at equations with floor and ceil functions...

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

Just upsolved div1B, as mine solution failed on the added systest. And now I am confused.

I did this (343430329) following the editorial, where I have ~516MB (twice as much won't fit right?). I have the input and $$$n \times n \times m$$$ memory (wlog $$$n \le m$$$).

When my submission failed after retest (343345702) I thought that it is fair enough as I haven't really proved my solution memory consumption (I do rectangle search and then delayed range minimum updates with some priority queue trick to have better constant factor). But now I look at it and I see that instead of having $$$n\times n \times m$$$ dp I store the push-min updates on range that I afterwards process. Number of updates is sum of length long-side borders of the rectangles from $$$\mathbb{S}$$$. So it is like $$$2 \times n \times n \times m$$$. I do up to 4x factor as I am not careful when borders are shared but it is rather easy to handle (if you got MLE to fix lol).

So it seems even if I do patches my solution doesn't fit. But it is also clear I have only 2 times more memory (well, there is std::vector overhead but I can manage). And the solution seems to me, well, careful enough, not abusing sets or segment trees.

So I dont understand two things regardless of the missing maxtest:

  • Am I wrong with my solution? Like, is it so bad to have 2x memory (1040 MB?) that it was not intended to pass?
  • Constraints + limits seem to be in this gray area, where they don't communicate what is expected and not expected to pass (sqrt time? sqrt time + memory? sqrt log time + sqrt memory? sqrt memory plain?). This is sometimes alright when model solution passes with a big gap but here we have $$$O(nm\sqrt{nm})$$$ time + memory as well. Why not make constraints 2 times easier or harder to be more transparent about the problem?

upd: actually, when I say 1040Mb, I also assume I store 4-byte integers — but 3-byte integers can break this gap as well.

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

    Initially I had no plans of letting $$$\mathcal{O}(nm \min(n,m))$$$ memory pass, but Proof_by_QED told me that probably I should allow a wider range of solutions. I was totally fine with that, and so I cranked up the ML to 1024MB which was the maximum ML possible. Looking back, I feel that this was a mistake, and I think I certainly should have tested the relatively worse solutions more thoroughly and I didn't. I was in a hurry for everything; both inside and outside this round.

    I think you can regard that line as "it might pass if you're lucky, or you might have to shave a few constants off". Other than that, the model solution uses $$$\mathcal{O}(\min(n,m)(n+m))$$$ memory and should be regarded as the "safe" solution.

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

    Every sqrt problem should be attempted to be optimized to linear memory. $$$n \sqrt n$$$ memory is always bad, so do that only if there is no other way

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

    when i looked at the problem, it felt like $$$O(nm\sqrt{nm})$$$ memory is too much. so i was surprised to see that the editorial uses that amount of memory. i used a nice trick to solve this "offline setmin queries" problem with little memory and time, and i don't see it being mentioned here, so let me share it.

    there is a standard problem "static RMQ". in this problem we have a fixed array and a bunch of range minimum queries. everybody knows we can use sparse table to solve this problem in $$$O(N \log N + Q)$$$ time. but then our problem feels very similar, we just kinda swapped queries and updates. this idea of swapping queries and updates is standard for segment trees but not that much for sparse tables. but we can actually use sparse tables to perform $$$Q$$$ setmin queries and restore the final array at the end in $$$O(Q + N \log N)$$$ time and $$$O(N \log N)$$$ memory. we just initially set all values of our sparse table to be $$$\infty$$$, and then whenever we have an update, we split it into two updates of length power of two, and update the corresponding cells of the sparse table. at the end, we just propagate DOWN (rather than up as in the normal sparse table) the values. after that, the lowest level of our sparse table stores the values of the final array.

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

In div1C/div2F, Can anyone explain the given DP relation?

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

I think you dont need to apologize because of div 1 B. In the past contests, it was normaly that you can pass pretests but fail systems. It reminds me about the old codeforces 8 years ago :)

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

The solution for Div1D1 felt almost the same as https://qoj.ac/contest/1738/problem/9129 after coming up with the idea that only suffix minimums are important.

But the problem seems way different

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

can anyone explain the DP part of Div2E/Div1B ? It seems quite a few people didn't quite get it (myself included).

UPD:Oh, I think I've figured it out. We just need to define dp[i][j] as the maximum possible answer for the row range [l, r], then set dp[i][j] = min(dp[i-1][j], dp[i][j+1]), and initialize the DP array using the identified rectangles.

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

When solving Div1C, I mistakenly interpreted "only if $$$a_i$$$ is a non-negative integer for all $$$0 \le i \le n$$$" as "$$$a_i$$$ lies in the range $$$[0, n]$$$". Unfortunately, the sample inputs didn’t clarify this ambiguity—perhaps because very few people make such a mistake. As a result, I encountered enormous difficulties while working on this problem. I didn’t realize my misinterpretation until the final few minutes, but by then, it was already too late. lol

I would like to ask: how should we solve Div1C if we add the constraint that $$$a_i$$$ is in the range $$$[0, n]$$$? The best approach I can come up with has a time complexity of $$$O(n\sqrt{n})$$$; is there anyone who can find a more optimal solution?

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

    How would you do it in the complexity that you're saying? Even that's interesting.

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

      I made some mistakes, I'm sorry. That my problem.

      My solution can only be effective when a is all -1, but perhaps this can directly calculate the answer using an equation (I'm not very sure)

      Specifically, it is equivalent to selecting x numbers from 1 ~ n, so that their sum<=n, clearly x<=sqrt n, and each time dp can solve in O(n), so it is n sqrt n.

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

I am still unable to understand what Div2B was asking and how to come up with the solution.

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

My solution for Rectangles uses $$$\mathcal{O}(nm)$$$ memory: 343421540

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

Problem 2160 C Submission id : 343463506 can someone pls tell where my code is wrong? my idea was to consider highest set bit of x and loop it over from highest set bit of n to 29 ( max int limit) and checking for n as a plaindrome in each case... the logic for starting from highest set bit of n was that either x or f(x) will have highest set bit greater than that of n and i can switch between my x and f(x)

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

    n < 2^30 but x can be greater than 2^30. I have taken a simple case where n = 2^15 + 2^16 i.e. set bit 15 and bit 16 to 1 and your code will give "NO" for this which is wrong, you should store all bits in vector and let z = number of trailing zeroes in binary representation of n , you should insert z zeroes to the beginning of vector and then check the palindrome. Here size of vector can be > 30 but you are only considering it to be <= 30.

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

For problem E, was it intended that solutions with large constants should fail? Otherwise why are the time limits so tight?

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

Problem D is insects ioi 22 easy version

»
6 месяцев назад, скрыть # |
Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

In 2160B, please note the correction b[i] - b[i - 1] = i - x except when undefined since f(y, i) - f(y, i - 1) = 0 for all y <= x and f(y, i) - f(y, i - 1) = 1 for all y > x.

Thanks

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

Hi, I didn't understand div2E (=div1B) solution. Can someone explain it in more details? Or suggest a different solution?

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

    Its just dp in columns with states as pairs of row indices. Say n<=m then dp[c][i][j] represents the minimum area possible for points (i,c) to (j,c). Then how we calculate this dp? Initially initiliase everything to INT_MAX. Then as you find (i,j,c1,c2) as rectangles in S, set dp[c1][i][j]to dp[c2][i][j] to area. When done with this, calculate dp[c][i][j] in all columns by looping over decreasing subarray lengths. dp[c][i][j]=min(min(dp[c][i][j], dp[c][i-1][j]), min(dp[c][i][j], dp[c][i][j+1])) and, this will give you dp[c][i][i] which will be answer for (i,c) grid point.

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

Propagation technique in ecnerwala's solution 343437238 to B is just mind blowing. Do we have similar problems that use the same technique?

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

chromate00, when will the codes arrive?

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

In problem D2 editorial I think this

$$$\ \text{opt}'(c, r) = \min_{1 \le k \le 3} \left( \min_{\text{opt}'(c - k, r) \le i \le r} L(i, k) \right) \quad \text{(when } c \gt 0\text{)} \ $$$

should be

$$$\ \text{opt}'(c, r) = \min_{1 \le k \le 3} \left( \min_{max(\text{opt}'(c - k, r) - 1, 0) \le i \le r} L(i, k) \right) \quad \text{(when } c \gt 0\text{)} \ $$$

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

Code is somehow not posted yet so here's my solution to 2E/1B: 343529349

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

I'm really disappointed because i thought for B for nealy 40 minutes and couldn't get the right solution. @#%@!%@!%!@!

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

can some pls explain the solution of Div2E in detail. I am unable to comprehend the editorial.

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

How can I make my solution for E faster 343557726? It's basically what the editorial says...

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

    I'm not 100% sure if this is the issue, but I think you just need to optimize how you iterate through the array. For example:

                                    for (int hh = h - 1; true; hh--) {
                                        for (int ii = i; ii <= j; ii++) {
                                            ans[ii][hh] = min(ans[ii][hh], sum);
                                        }
                                        if (a[i][hh] == '1' && a[j][hh] == '1') {
                                            break;
                                        }
                                    }
    

    Generally you want to iterate through an array with the inner loop being the last "indexer", because otherwise it results in a large constant factor. What I personally did was

    Spoiler

    Also pragmas might help (they cut my solution runtime by 400ms)

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

Can anyone help me on my solution to problem Rectangles Div 1B, I'm unable to optimize its memory used any further, My submission: 343564145

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

Could anyone solve Div2E/Div1B using DSU?

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

For the editorial of problem 2E/1B, I think it would be nice to mention that $$$dp[u][d]$$$ means the area of the smallest rectangle that covers the range $$$[u, d]$$$ of column $$$j$$$. The transition is easier to understand with this assertion.

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

A better solution for div1.F that uses $$$\le 40n+m$$$ queries:

Iterate the answer $$$d$$$ from small to large, and try to get all $$$f(i,T)=d$$$. Repeat this process until we have $$$m$$$ answers.

For every $$$i$$$, we have a range $$$[l,r]$$$ meaning that it's possible to have some $$$l\le T\le r$$$, and $$$f(i,T)=d$$$. We then ask for $$$f(i,mid)$$$. If $$$f(i,mid)\le d$$$, then we proceed to solving $$$[l,mid-1]$$$ and $$$[mid+1,r]$$$.

On the other hand, suppose $$$f(i,mid)=v$$$ and $$$v$$$ appears at time $$$t$$$ (this time is fixed at the beginning since both ways of moving will always make the $$$x+y$$$ value increase by $$$1$$$). Then we can say for sure that for all $$$T\in [t,t+i-1]$$$, $$$f(i,T)\ge v \gt d$$$. Which means that we can skip this range, and go on to solve $$$[l,t-1]$$$ and $$$[t+i,r]$$$.

We keep a table of all known $$$f(i,T)$$$ and don't have to ask for repeating ones. If a pair $$$f(i,T)$$$ is asked and it is included in the answer, it contributes to the $$$m$$$ queries. Otherwise, for any $$$f(i,T)$$$ asked and not included in the answer, it will eliminate at least $$$\min(\frac{r-l+1}2,\frac i2)$$$ values for which we will never ask.

This way, the total number of queries is $$$m+\sum_i 2\times\frac{2n}i=m+4\log n$$$, where $$$40n+m$$$ is definitely a safe bound, considering that there are some waste. And by testing, this solution can pass all tests within $$$35n+m$$$ queries, which is much better than the official solution.

There is a small issue when implementing. Doing this directly has a time complexity of $$$O(n^4)$$$. However, notice that except $$$d=1$$$, we only have to consider pairs $$$(d,i)$$$ where $$$d$$$ appears as some answer received when asking about $$$i$$$ previously. This leaves us with only $$$O(n^2)$$$ pairs to solve, and the complexity is then $$$O(n^3)$$$.

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

I just realised Problem D1E was a reference to Super-Slow-Internet-san

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

The editorial for Twin Polynomials has a typo.

The claim "Since $$$a_0 = −1$$$, we can only consider $$$i \gt 0$$$ and get $$$a_i = \sum_{a_j = 0} j$$$ automatically."

should be corrected to "... and get $$$a_0 = \sum_{a_j = 0} j$$$ automatically.".

I believe the author's intent was to say that the coefficients $$$a_1, a_2, ..., a_n$$$ uniquely determine $$$a_0$$$, so it should really say $$$a_0$$$ instead of $$$a_i$$$. It is a small error, but I wanted to point it out because I got stuck in that part for some time.

wuhudsm can you confirm if my understanding is correct about the typo? Or did I completely misunderstand the editorial?

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

The fact in d1E that we can find the $$$n$$$ power of a polynomial of degree $$$k$$$ in $$$O(nk^2)$$$ feels like magic to me. How can we just differentiate in 2 different ways and get something of what should be identical polynomials? And is this idea well-known? I just can't imagine that I'd ever come up with something like that, it's a long leap of faith

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

i think it would better if the code solution was mostly written in C++ or you should consider python and C++. Because the majority of the participants enter the competition by writing C++ code.

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

My submission for question D

Can anyone tell, why is it giving tle. According to me, time complexity of my code is O($$${n^2}$$$).

Please help.

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

I couldn’t understand the editorial for 2160B - Distinct Elements. Could someone please explain it to me?

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

Maybe i'm not right, but i think there is a typo in editorial(problem C div 2). It says that if z is odd and middle bit is 1 then we cannot find such x. Counterexample: n = 6 = 110. x = 1101, f(x) = 1011. We can see that z = 3 is odd and middle digit is 1, but x exists. So i think this condition should apply to y. If i missed something, please prove me wrong.

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

When you take a number and XOR it with its bitwise reverse, the result will always have an even number of 1s (set bits) — never odd.

i think it is true by this we can solve c by just if ,else.

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

div2F/div1C tutorial is kinda not correct? you cant just validate using only dsu, either with a lot of extra work, either you should just fill in the blank according the size2 scc rule straightly and check if the final sequence has only -1's, 0's and scc's of size 2.

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

In Div1C, setting $$$a_i \le 10^9$$$ instead of $$$a_i \le n$$$ is evil.

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

For part 2.3 of div2G1/div1D1: when you discard all the lines $$$j + 1, ... i$$$ and insert the line with the minimum $$$opt(1,j)$$$ we know it will be the optimal line for some suffix (because if we remove all the lines that will never be part of the convex hull $$$min(a_j, ... a_i)$$$ will be non-decreasing and thus $$$dp_j$$$ will have to be non-increasing), thus we can binary search on the leftpoint of the suffix the replacement line will be optimal for.

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

Here's my own solution to 2159B - Rectangles, based on AksLolCoding's implementation.

If you are struggling reading my solution, read it along side with the implementation would help you visualizing the general idea.

For all pairs $$$i, j$$$ of rows, with $$$i=1,2,...,n$$$ and $$$j=n,n-1,...,i+2,i+1$$$, we enumerate columns $$$k=1,2,...,m$$$:

  • Let's define $$$mn_k$$$ as the minimum area of a valid rectangle when we are iterating through the $$$i$$$ row that covers the column $$$k$$$, and $$$pos$$$ as the set of all columns $$$k$$$ such that $$$G_{i,k}=G_{j,k}=1$$$.

  • When enumerating through column $$$k$$$, we insert $$$k$$$ to $$$pos$$$ if $$$G_{i,k}=G_{j,k}=1$$$.

  • After finishing iterating all columns, we have $$$pos={k_1,k_2,...,k_u}$$$, then for each pair $$$(k_1,k_2),(k_2,k_3),...,(k_{u-1}, k_u)$$$, we update $$$mn_v=\min(mn_v,wh)$$$, for each $$$v=k_u,k_u+1,k_u+2,...,k_{u+1}$$$, with $$$w$$$ is the width between column $$$k_u$$$ and $$$k_{u+1}$$$ and $$$h$$$ is the height between row $$$i$$$ and $$$j$$$.

  • Then we just need to update the answer to the current row $$$j$$$ before switching to the next row $$$j$$$, $$$ans_{j,k}=\min(ans_{j,k},mn_k)$$$, with $$$k=1,2,...,m$$$.

  • Do the same before switching to the next row $$$i$$$, $$$ans_{i,k}=\min(ans_{i,k},mn_k)$$$, with $$$k=1,2,...,m$$$.

By enumerating through all rows and columns this way, we will always find the minimum area of a valid rectangle covers each cell:

  • Because we are iterating through $$$j$$$ with decreasing order, so a rectangle covers the cell $$$(j+1,k)$$$ would of course covers the cell $$$(j,k)$$$ as well.

The complexity here is $$$O(mn^2)$$$, but if $$$n$$$ is large, $$$n^2$$$ can be very large and exceed the time limit. So we need to swap $$$m$$$ and $$$n$$$ if $$$n \gt m$$$, and ensure that $$$mn^2$$$ is not greater than $$$mn\sqrt{mn}$$$.

The overall time complexity is $$$O(mn\min(m,n)) \le O(mn\sqrt{mn})$$$, and the memory complexity is $$$O(\min(m,n)(m+n))$$$.


Code (AksLolCoding)
Code (My code)

If you find this helpful, please give me an upvote. Thank you a lot!

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

The solution for Problem B (Distinct elements) is wrong here:

bi−b(i−1)=i−(i−x)=x //wrong here

it should be: bi-b(i-1) = i-x then, x = i-(bi-b(i-1))

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

I think theres a mistake in the solution of B: instead of bi−bi−1=i−(i−x)=x it should be bi−bi−1=(i−x)

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

How to improve on solving problems like C and D?