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

Автор ch_egor, 3 года назад, перевод, По-русски

Спасибо за участие!

1501A - Леша и поезд придумал Aleks5d, а подготовил 4qqqq

1501B - Торт Наполеон придумал и подготовил KAN

1500A - Поеду домой придумал и подготовил wrg0ababd

1500B - Две люстры придумало жюри, а подготовил Siberian

1500C - Сортировка матрицы придумал Endagorion, а подготовил NiceClock

1500D - Плитка для ванной придумал meshanya, а подготовил KiKoS

1500E - Фокус с подмножествами придумал и подготовил isaf27

1500F - Прыжки по шкафам придумал и подготовил Akulyat

Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
  • Проголосовать: нравится
  • -273
  • Проголосовать: не нравится

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

Thanks for the round and the fast editorials!

UPD: It seems that many participants hate this round because of unclear statements, weak pretests or main tests, too hard time limits and so on. But I think these problems are interesting and challenging, aren't they?

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

Thanks! :)

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

1A can be solved using FFT. 109885329

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

What does "C" denote to in going home editorial ?

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

Two logarithms in B and logarithm in C and these TLs? Are you crazy? ;_;

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

    Isn't there a linear algorithm for B, My code[submission:109895054]passed tests but I don't know if its correct considering many smart people didn't get this algorithm

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

Div 2 C was hard :(

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

min(n^2,n+C)......I think too much.

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

    How is O(n2) solution working when 4 <= N <= 200000 ?

    I know the time complexity given above is O(min(n2, n+C)). Where is this (n+C) coming from ?

    When the answer is "NO" we are iterating over all the possible pairs O(n*(n-1)/2). So when the value of N = 200000, shouldn't it give TLE ?

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

      The answer will not be "NO" when $$$n$$$ is big enough.

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

      You can think of the pigeonhole principle.

      Remember that there are always four distinct indices $$$x, y, z, w$$$ such that $$$a_x + a_y = a_z + a_w$$$ ($$$ = S$$$) when there are at least four distinct pairs of indices $$$(x_1, y_1), (x_2, y_2), (x_3, y_3), (x_4, y_4)$$$ (indices may be repeated across them) such that $$$a_{x_1} + a_{y_1} = a_{x_2} + a_{y_2} = a_{x_3} + a_{y_3} = a_{x_4} + a_{y_4} = S$$$.

      Let's imagine we are running our $$$\mathcal{O}(n^2)$$$ bruteforce and trying every pair; for every pair $$$(i, j)$$$ we compute its sum $$$a_i + a_j = S$$$ and increment the count on how many times we have seen the sum $$$S$$$.

      Given that the maximum sum of any pair is $$$2*C$$$, the "longest" it would take the bruteforce to see one sum $$$S$$$ occurring four times is around ~$$$3 * (2 * C) = \mathcal{O}(C)$$$. Therefore, if a solution exists, it will be found in time $$$\mathcal{O}(C)$$$. If there's no solution (we tried all pairs), it was the case that (roughly) $$$n^2 \le 3 * (2 * C)$$$ (or something close to this).

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

Can I see the model solution to B, with complexity O((n+m)⋅log(n+m)⋅log(k⋅(n+m)), that passes the constraints? How was the TL set? Thanks

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

    +1

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

    I'm curious about the running time of the author's code and if he had done strict optimization on constant.

    Or maybe the author thought 1 second equals to 1e9 complexity on codeforces?

    I'm considering adding "#pragma GCC optimize("Ofast")" into my default header, though my code used 1544ms this time without this ;_;

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

      I can't imagine that complexity passing even with some constant optimizations. Even if it passed, it would be bad to set TL based on a heavily constant optimized solution with terrible complexity. At least you passed, I couldn't fit my O((n + m)log(i64)) into TL, but that might be just because I'm weak :D. (also I don't have any lib so I copied from cp-algo and apparently it's slow xd)

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

        Actually I too can't imagine this complexity can pass the test in this TL. And I think the TL of this problem is undoubtedly inappropriate, and it seems like a naive mistake.

        Yet I'm simply curious about what had happened when this limit was being set. As far as I know, some authors would just set the TL by the running time of his/her code times 2 or even 1.5 without thinking twice.

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

        BTW, My complexity is also O(n+m)log(1e18), no two logarithm but still not too far from the TL.

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

    My solution passes, but I have log(n)^2.109863770

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

    There is a linear algorithm right?Why not explain that in editorial?(My linear algorithm submission:109895054)

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

Div.1C has some similarities with Bucket Sort.

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

I decompose 2C into several cases:

1) We have 4 copies of a value X (e.g. 1 1 1 1 2 3) => YES

2) We have 2 or 3 copies of a value X; and we have several such X (at least 2), (e.g 1 1 2 2 2 5 10) => YES

3) We have 2 or 3 copies of a value X; and there is exactly one X like that (e.g. 1 2 2 2 100 7 9) => two pointers for checking whether we have u and v such that u < X < v and u+v = 2*X => YES/NO.

If YES, it is ok. Otherwise, we remove duplicated elements and continue with case 4.

4) We have only distinct values (e.g. 1 2 5 9 11 13 ...)

If N*(N-1)/2 > 5*10^6: we will have two different pairs (x,y)and(z,t) that meets the condition; because of the Dirictle lemma. Just check bruto-force the first sqrt(10^7) elements.

Otherwise, perform O(n^2) algorithm to check.

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

    Can you elaborate on Dirictle lemma?

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

      It is something like : if you put N items into M boxes with N>M; you will have a box with at least 2 items.

      So, given that we have an array of size N with distint non-negative values and we have n*(n-1)/2 pairs (u+v), and if n*(n-1)/2 > 5,000,000; we should have a YES answer.

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

        Is it same as pigeon hole principle?

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

        Great explanation! it helped me to completely understand why brute force sol. works.

        Thanks.

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

    Why do we have to check only sqrt(10^7) no.s , Here we are on addition so shouldn't we check till 2.5*10^6 , for each loop

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

Can you unhide the main tests? I can't wait to find why I FSTed:(

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

Div1 B can be solved in O(n log k). Crt and Gcd is not necessary .

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

    code:

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

      Any tutorial?

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

        Find the loop section and binary search

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

          I don't understand. Do you mean precalculate length lcm(n,m) and find answer to k using binary search? I am a little dumb here becuz the loop section's collision might need O(nm) to find if n and m are coprime.

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

            You can see the "while(!vis[now])" part in my code , it found all the loop section.

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

    I might be wrong but I believe if one uses CRT, but not BS on the answer, it is O(NlogN). We compute the values mod mmc(N,M) that have the same color.

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

    It could be solved in O(N + M) to. Binary search is not necessary, one could just "simulate". In case someone is interested: code

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

    If my math is correct, it can be solved in O(N) (or smth like O(N+M+log(N+M)), but linear in general)

    126387236

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

This editorials is so fast that I'm be so surprised of it!

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

I have a randomised solution for div2C/div1A and I'm not sure if I cheesed system tests or if it's supposed to pass. Can someone take a look at it and hack if possible? Otherwise, if it's supposed to pass, can someone tell me the probability of failure?

Submission: 109876872

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

I got a FST in Div1B.

But when I submit the code again after contest , it accepted (but 1981ms).

And when I submit the same code again with C++17(64) , it accepted and only ran 1653ms.

What a pity...

My submisson during contest:109857178

Submisson after contest:109891513

With C++17(64):109891826

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

I found the GFG page, but looking at it I thought it wouldn't pass. After the contest and reading some comments here, I thought it just might.

I tried, and it got AC. Smile in pain. Hehe.

GeeksForGeeks article

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

Please can someone explain me this : During the contest I submitted ABC and there it said pretest passed and now it is showing -1 in A and C, saying WA in tc 6(for A) and TLE in C problem. How does this happen?Should not they show this during the contest, that i have done 2 questions wrong ?? Please if someone could help me understand what happened ? I am really frustrated rn

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

    Since it would take too much time to run over all the testcases during the contest, Codeforces divides the testcases to be "pretests" and "system tests".

    Passing the pretests doesn't mean that you solved the problem (though it should...).

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

Good contest with strong pretests, especially in problem B and problem C.

What's more, the tl of problem B and the ml of problem D are very friendly. No one can get TLE or MLE on them.

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

    I think that you should say clearly that it's a sarcasm, it might be hard to get it.

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

    Can't speak for D, but, unless my solution is very wrong and tests are extremely weak, binary search in div1B isn't needed at all. In fact, I solved it in $$$O((n + m)\log(n + m))$$$, where the $$$\log$$$ comes from a single sorting of a vector with up to $$$\min(n, \, m)$$$ elements.

    Sketch of solution. Iterate over the colors and make a vector $$$s$$$ of all solutions to the system that you find (if for some color there are no solutions, ignore it). Then sort the vector. Now set $$$ans$$$ to $$$\displaystyle \text{lcm}(n, \, m) \cdot \left\lfloor \frac{k}{\text{lcm}(n, \, m) - \text{size}(s)} \right\rfloor$$$ and reduce $$$k \mod (\text{lcm}(n, \, m) - \text{size}(s))$$$. Finally, iterate over the elements of $$$s$$$ and stop at the first index $$$i$$$ such that $$$s[i] - i \ge k$$$. Then it is easy to update $$$ans$$$ to the correct value.

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

How to solve Div1B/Div2D ?

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

Can anybody please explain why this solution for div2 A is giving wrong answer https://codeforces.com/contest/1501/submission/109849523

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

109860426

Who wants to hack my randomized div1A?

For n <= 150, I use a quartic brute force.

For n > 150, I use MITM, where I partition the array into two halves, and randomly select 10^6 pairs from each half, and check for any common sums.

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

ML in D was brutal. If only $$$q \le 9$$$ instead of $$$10$$$ or number of colors was up to $$$2\cdot 10^6$$$ instead of $$$2.25 \cdot 10^6$$$ it would really be easier xd

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

Div-2 C solution in gfg:

some modifications will do

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

Shitty Round especially statement of problem DIV2A.

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

109889803
For 1500C - Matrix Sorting , the $$$O(nm^2)$$$ approach could be optimized to $$$O(\frac{nm^2}{w})$$$ using bitset, which could pass the tests.

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

    Yes, that's what I did in the contest. I really think it's a good problem, but the limit seems quite tight. I douted whether it would pass before submitting (it passed though).

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

    $$$O(nm^2)$$$ can be pass the tests too. So Incredible! 112190603

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

I had figured out a $$$O(nm^{2})$$$ solution for 1C, but now I don't even understand how the editorial reaches $$$O(nm^{2})$$$, let alone understanding optimising it to $$$O(nm)$$$. The editorial is hard to understand.

I think the optimising part made it too difficult a problem for its position as 1C ?!

In particular, can someone please explain this part:

If two rows are in the same class, then the columns that we applied had the same values. Then, we need to find a column that does not break the sequence between the rows inside each of the classes. Let's iterate through such a column every time.

What values are we talking about?

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

An alternative approach for Div1A.

Let us prove that if $$$n > \sqrt{8\max a} + 2$$$ then we can always find such a quadruple. Indeed, sort $$$a$$$ in ascending order and consider the differences $$$a_2 - a_1, \, a_4 - a_3, \, \dots, \, a_{2k} - a_{2k - 1}, \, \dots$$$ These are $$$\left\lfloor \frac{n}{2} \right\rfloor$$$, so there are two of them which are equal. If that weren't the case, we would have

$$$\displaystyle a_n \ge \sum_{k = 1}^{\left\lfloor \frac{n}{2} \right\rfloor} (a_{2k} - a_{2k - 1}) \ge 0 + 1 + \cdots + \left(\left\lfloor \frac{n}{2} \right\rfloor - 1\right) = \frac{\left\lfloor \frac{n}{2} \right\rfloor\left( \left\lfloor \frac{n}{2} \right\rfloor - 1 \right)}{2} > \max a.$$$

Let $$$i, \, j$$$ be such that $$$a_{2i} - a_{2i - 1} = a_{2j} - a_{2j - 1}$$$. Then $$$x = 2i$$$, $$$y = 2j - 1$$$, $$$z = 2j$$$, $$$w = 2i - 1$$$ is a solution.

Now we proceed as follows. We sort $$$a$$$, iterate over the even values of $$$k$$$ and check if two differences $$$a_{2k} - a_{2k - 1}$$$ are equal. If this is the case, we are done. Otherwise, $$$n < \sqrt{8\max a} + 2$$$ and we can bruteforce the answer in $$$O(n^2)$$$.

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

    sorry but I can't figure out how $$$n > \sqrt{8\max a} + 2$$$ is calculated, could you please give an explaination?

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

      You gotta solve the equation $$$\frac{\left\lfloor \frac{n}{2} \right\rfloor\left( \left\lfloor \frac{n}{2} \right\rfloor - 1 \right)}{2} > \max a.$$$ to get this. The inference makes sense, however, I don't quite understand how you bruteforce the answer in $O(n^2)$。

      UPD: I now understand, use the method as editorial. But then you don't need to do those survey beforehand :<

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

        Exactly as in the editorial solution. Actually, I realize now that the first part isn't needed at all. Because of the proof in the editorial, the second part alone (bruteforce) is sufficient to solve the problem with the given constraints.

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

        Thx for the explaination and I also wonder how to bruteforce in $$$O(n^2)$$$

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

1500A going home. I notice that ai<=2.5*10^6 but didn't investigate into that.. Indeed, $$$1<=ai+aj<=5*10^6$$$ for arbitrary i,j. And if we have n distinct elements, we will have $$$\frac{n*(n-1)}{2}$$$ pairs of different pair of (i,j). If $$$\frac{n*(n-1)}{2}>5*10^6 => n>=3162$$$ you are guaranteed to find an answer. Well, doesn't help to solve this problem.

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

I feel like this approach for div1A/div2C is right but it FSTd. Can someone tell me why?

So first i rewrite the eqn as ax-az = aw-ay. Now I just need to find 2 pairs of indices such that their differences are the same.

For this, I store all elements in a frequency array and iterate over all differences.

for(int i=0;i<N;i++)
    for(int j=0;j+i<N;j+=i)
        //check if j and j+i are present in the freq array
        //Find 2 such pairs and that would be our answer

My submission

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

div-2D/1B can be solved in linear time. We just need to calculate for each starting position in 1st array, how many matches will be with 2nd array in next m indexes. Here's my AC: 109899040

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

    Yup I used a similar approach. Code

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

      Yes, it is too similar lol.

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

        Can anyone of you explain your submissions as it seems that some mathematical principles are hidden in some beautiful lines written out there. Thanks.

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

          First I made the 1st array greater than 2nd by swapping.

          I have made an array named 'c' of size n, such that c[i] represents the no. of dismatches (a[i]!=b[j]) in the next m days if we start from a[i].

          Mathematically, c[i] = no. of j's such that a[(i+j)%n]!=b[j] and j=0 to m-1

          Initially all c[i]=m (we assumes all dismatches). Now we can iterate the 'b' array.

          If b[i] is not present in array 'a', then b[i] won't cause any match irrespective of starting index (won't effect any c[j]). We will simply continue.

          otherwise if b[i]==a[j] (you can use an additional array/map to find that), we should decrease c[(i-j)%n] by one because we will find a match when we start from (i-j)%n after j indexes.

          Thus we obtain c array. Let x=0. Now we can just push_back c[x] in a vector and change x to (x+m)%n until it again reaches x=0 ( cycle formed)

          after that it's just trivial.

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

Can anyone explain why brute force worked in C (going home) even though the constraints are 4≤n≤200000? 2*10^5 should require an O(n) or O(nlog(n)) solution so how O(n^2) worked?

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

    Because since 2.5*10^5 is the upper bound on every element the maximum sum of 2 elements can be 5*10^5. Now if you just iterate to get all possible sums they will all be below 5*10^5 and in 1 iteration you get 1 new sum, otherwise you break. So you will never TLE.

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

      *upper bound on every element is 2.5*10^6

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

        Alright, but it's still more than enough. The solution is actually O(n).

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

          now i am more confused....

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

            Ok imagine you have a million elements but upper bound is say 10, do you need to do O(n^2) over a million elements to confirm that you will get a repeating sum? No, as maximum possible sum of 2 elements is only 20 you will only have at maximum 20 different values of sum possible, this is the whole basis of this problem. As another user suggested this is known as pigeonhole principle.

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

What is the variable "y" in 1B's tutorial?

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

Thanks for fast and clear editiorials!

I quickly(I hope so) solve two problems, when I come to think about C, I had a challange. But finally I solve it. And the great thing is I have a rank of 239! I'm really excited about that:-)

The problems are really great and I enjoyed it a lot, thanks!

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

In Div2 C ( Div1 A ) why the brute force using map and checking sum of 2 pair of indices passes the time limit. Its time complexity is O(n^2) still it passes. Code: https://codeforces.com/contest/1501/submission/109901974

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

    I Misread...

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

      Actually i was trying to show that even using map, brute force O(n^2) is getting passed .. my question was- why is this getting passed through the time limit ?

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

        Because maximum element is 2.5*10^6 so maximum sum of 2 elements is 5*10^6. So you can get at max 5*10^6 different values of sums before encountering a repetition. So once you find a sum again for different indices you can just break the iteration. That's why time complexity is given as min(O(n^2), O(n+C)).

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

My code for div1B got TLE result. submission

After using fread,it accepted. submission

The complexity of the code is $$$O((n+m)log(nm))$$$

So , why is the time limit so hard ?

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

again my A FST. is it weak pretest or my blunder? A Submission

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

will someone tell me what is wrong with this code https://codeforces.com/contest/1501/submission/109882653 ? it is showing runtime error on test 8.

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

Why aren't results for div 2 out yet?? I see div 1 results are already out.

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

У меня неверное решение которое получилось загнать https://codeforces.com/contest/1501/submission/109915155 Добавьте тесты посильнее

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

[TWO CHANDELIERS] Can someone explain me over what variable you can do binary search? I don't get the solution at all :(

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

This could just be my own perception, but since restrictions on contest writers were tightened, I have found the contests much more difficult. Today I couldn't solve a single question in Div 1. I think that's the first time that's ever happened, but in general the recent contests have been tough.

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

    :< Dude you are really hardworking. This used to be a complaint but it is now a comfort from me after checking your profile.

    Keep up and do some problems that you never hear of. Wish you luck.

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

Very beautiful, careful and short solution by olympiad participant teraqqq. May help to understand the solution.

https://pastebin.com/uhhe3c4v

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

    What exactly does vector<int> cut keep track of? Seems like it stores some kind of property for the rows?

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

      In the final state of B, the equivalence classes are sub-arrays, so we store did we cut our classes or not.

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

Sadly ch_egor have not authored any problem but suffered downwotes for managing the contest and problemset. It is not fair.

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

In Div2 C, I used an intuitive approach to solve that worked. Basically, I iterated over differences (ax — az) from 0 to k*C/N, where C = 2.5*10^6, N is the input size, and k is some constant (say 2) and then I checked whether four such indices exist or not. My question is how to prove that only checking first k*C/N differences works? Also, what is the tight lower bound for such k?

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

How are we expected to know that the actual value of n used in the main tests is much smaller than the given constraint in div2-C question? An O(n^2) solution should not be accepted according to the given constraints but many people got away with it due to weak test cases. This should be rectified somehow

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

I have trouble understanding problem div1 A / div2 C

Why is the condition in the editorial sufficient? If we have 4 pairs such that their sum is equal then there is a solution. However, that doesn't imply that there will always be 4 such pairs if there is a solution to the problem.

In other words, what is the proof that there exists a solution to the problem if and only if there are these 4 pairs that are described in the editorial?

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

Here is the normal solution of d1a instead of the authors' unobvious solution:

If $$$n<10000$$$ run the $$$n^2$$$ solution, else sort the numbers and find the pair of pairs of adjacent numbers with the same difference, also the indices should be different. It always exists because $$$10000^2 > 2.5 \cdot 10^6$$$.

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

I submitted the code when the overall evaluation failed in the competition and passed it directly after the competition. The machine was too slow during the overall evaluation, which led to unfair treatment. Please restore it to me!!!!!

during

http://codeforces.com/contest/1500/submission/109859256

after

http://codeforces.com/contest/1500/submission/109932270 http://codeforces.com/contest/1500/submission/109931959 http://codeforces.com/contest/1500/submission/109931910

Quite the same

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

How to construct a sequence of number for n = 1570 whose answer is "NO" for div1A/div2C ? I found that 4-th example is that situation, however, I can't construct it. Can someone give me an idea ?

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

DIV2 C question was hard to think how it works in N^2 approach even N was in that range which generally doesn't fit in N^2 approach .. many of those (not all of them) get accepted to that question without knowing proper reason.. LOL..

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

    Even absolute newcomers with just a little idea of complexity won't write O(N^2) solution at this constraints without reasoning. So, what are you talking about? They at least got the intuition and getting it isn't hard. It's just getting the fact that if you have large N, then you would have duplicates in sum simply because of so much options to choose sum and limited options for sum.
    So, not actually many of them, only like 1-2% at most without knowing reason tried out O(N^2).

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

Problem C. Going Home. In statement n is <= 200000. So why O(min(n^2,n+C)) doesnt have TLE?

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

In the problem B, the numbers are distinct which isn't stated in the statements. That's a major issue.

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

what is "y" in the editorial of div1B/div2D?

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

They added few more test cases in Div 2 Problem C. Why my previous AC code is giving TLE on Test Case 73?

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

I haven't seen anyone else do this, but div. 2 B can be solved with Fenwick. 109919812

The idea is basically to keep a BIT of the number of layers of syrup on each layer of cake.

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

I'm going crazy. Can anyone tell me why my solution gives WA on test 12? problem div2.D and my code, Thanks.

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

How is C:Going Home Accepted in quadratic time?

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

div1A I got ac,but my code 110017025 was wrong wrong test: 5 1 1 1 1 4

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

[Div-1 'B']

If n and m are not coprime, participant can make transition (n,m)→(ngcd(n,m),mgcd(n,m)), solve new equations, and then make reverse transition

How to do that?

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

Can somebody please tell me why my code:110064321 TLEs in Div.2D and any possible optimization I can do? Thanks.

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

My solution for d works in O(max(n, m)) time. So first you check if the solution will be found after n*m days(because that will 100% get both sequences lined up again). To do so you take the smaller array and find how many same numbers it will have in every cycle(1 cycle is min(n, m) days) in bigger array. For example if you have 3 2 1 0 and 3 1, at cycle 0 (3 2 : 3 1) you will have 1 same occurance, at cycle 1 also(2 1 : 3 1) and in others 0.To do so fast you find where every element from smaller array belongs in bigger and to get the position of cycle subtract the index of element in smaller array(so 1 is on index 2 in bigger array but because it is second element in smaller it will belong to 2 — 1 = 1 cycle). After that you just n times add number of different elements in cycles (to do so you just have i — cycle you are currently at which is 0 at start and with every iteration it will become (i + m) % n because 1 cycle is m days so you move m elements on bigger array). After you add all the values(lets say into SUM) of numberofdifferentoncyclei you can check if that number is bigger than k and if it is you add to your answer(int)(k / sum) * n * m and subtract from k (int)k / sum * sum so we now know that k < sum. After that we can just do one more iteration over cycles to find at whichn our sum will become greater than k and get our answer. Check the code for better understanding.110062516

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

For 1500A - Going Home, I found the editorial's solution really hard to optimize to fit into the 2s time limit. However, if we first do an $$$O(n)$$$ pass to filter out the test cases where there is a value with frequency $$$\ge 4$$$, or at least two non-unique values (in those cases, a solution can be easily constructed), we could then know that the solution, if it exists, must involve four distinct values. Thus we only need to store up to one pair for each sum (finding the second disjoint pair will allow us to construct the solution) This significantly improves the constant factor for the solution, and easily passes in Kotlin.

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

Matrix Sorting's tests can be passed using O(n*m*m) solution.

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

TL for Div 1 E is tooooooo tight !!!

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

.

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

can anybody please help me with the dynamic programming solution of napolean cake question

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

can any one give a TC to find why my submission gets TL ?