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

Автор rotavirus, история, 4 года назад, По-русски

Authors:
d2A: rotavirus
d2B: nvmdava
d1A: nvmdava
d1B: rotavirus
d1C: nvmdava
d1D: rotavirus
d1E: antontrygubO_o

Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Разбор задач Codeforces Round 618 (Div. 1)
Разбор задач Codeforces Round 618 (Div. 2)
  • Проголосовать: нравится
  • +110
  • Проголосовать: не нравится

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

Автокомментарий: текст был обновлен пользователем rotavirus (предыдущая версия, новая версия, сравнить).

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

Auto comment: topic has been translated by rotavirus (original revision, translated revision, compare)

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

How is (a|b)-b == a&(~ b) ?

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

    you may see it with an exemple :
    f(5,3) = 5|3 — 3 = 7 — 3 = 4
    binary representation : 101 &(~011) = 101 & (100) = 100

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

    A | B has all the bits where A or B have 1, set to 1.

    A | B — B has only those bits set to 1 where A has a 1 but B doesn't have a 1. If B had a 1, then A | B would have a 1 in that position and — B would set that bit to 0.

    So it is equivalent to A & ~ B

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

      i got it (a|b)-b=a&~b,but how to approach towards the answer from there

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

        Only the number which you put first is taken as it is and the others have ~ added to them. So maintain prefix and suffix of ~ &. Answer would be maximum of pref[i] & $$$a_i$$$ & suff[i] for all i. pref[i] is the value of all the elements from 1 to i-1(using the ~ & operation) and suff[i] is the value of all the elements from i+1 to n(using the same operation).

        The editorial explains it better so you might wanna read that :)

        Check this submission for reference.

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

      Understood this one rather than the editorial. Thanks!

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

      Nice explaination

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

    a|b can be written as: a + b — a&b

    subtract both side by b =>
    or a|b — b = a + b — a&b — b
    or a|b — b = a — a&b
    or a|b — b = a&(1-b)
    or a|b — b = a&(~ b)

    Edit : Note that 1 here represents all the bits where a is set as any set bits apart from it is out of our concern

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

      In 2nd last statement, you have used the identity that a&b — a&c = a&(b-c). How do you prove this?

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

        Hint : a — b = a&( ~ b)
        Although, the common element I took out was U or INT_MAX Edit : Just to clear out confusion here ,
        I didn't prove a&b — a&c = a&(b-c) ,
        rather a&U — a&c = a&(U-c) , where U is considered as all bits set

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

      Can you refer to any good resource to study bitmasking?

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

    For (a|b), let's define those bit positions which is 1 in b as POS, what (a | b) does is to make those POS in a become 1 (0 — > 1, 1 — > 1), and what (-b) does is to make those POS in a become 0 (1 -> 0), so as a result, what (a|b)-b does is to make those POS int a become 0, which is equal to a&(~ b).

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

    Corrected Solution :-

    (a|b) — b

    Now, a-b = a and (not b)
    So

    a|b — b = (a or b) and (not b)
    = (a and (not b)) or (b and (not b))
    = (a and (not b)) or (0)
    = (a and (not b))
    = a & (~ b)

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

    (a|b)-b = a^b — b = ab' + a'b — b = ab' + a'b — b.(a + a') [since a+a'=1] = ab'+ a'b — ab — a'b = ab' — ab
    = a.(b' + b') [since b' = -b] = a.b'

    [here, a' means complement of a]

    hence, the proof.

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

    You can imagine it using Venn Diagram if you have heard about it.

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

Please add a reference to this editorial in the round announcement post so that people can find it easily. Thanks.

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

Thank you for the wonderful contest. I really liked problem C of div2. The trick was to see what the operation is exactly doing!

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

I hate when the code is not included.

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

Finally became a specialist after veryyyy long time \(^o^)/

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

What is the logic behind Div2/E solution?

I am not able to get it. Someone please help....

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

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

Guys, does anyone have a non-geometric solution for Water Balance?

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

    Is not it slow to get AC?

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

    Yes. You can see all the water tanks as a succession of groups. Initially all groups have size 1. While you can find 2 adjacent groups, such that the left group has greater average volume than the right group, merge them. Here is my solution. It's not very well written and might be hard to read.

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

    Here is my O(n) solution based on deque.

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

      Using non-decreasing queue to solve this problem is a very simple way. Monotonic queue and monotonic stack both classical algorithms. Thank you for providing such a simple way.

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

      I like your solution. Can you give more insight on usage of 'eps'. What might happen if we will not use it.

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

        I just wanna make sure it will be true when tmp == Q.back().val.

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

        I think it is necessary to use 'eps' only when calculate whether two double number are equal.It mean we can't use == to calculate whether two double number are equal.If we want to calculate, we can use follow way. assume a and b are double.

        if(abs(a-b)<eps)
            cout<<"equal"<<endl;
        else
            cout<<"unequal"<<endl;
        

        In my opinion, I don't think it is necessary to use 'eps' when use < > <= >= operator. Sorry my poor English

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

    here is my solution I used stack

    Yo should notice the fact that the each number must be smaller then the next numbers

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

Wish I'd noticed the simplification in C... Ended up using a segment tree on |

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

I solved Div1_C with CHT.

We want to know minimal value of a[1] so we can binary search it. When we get it we should get minimal value of such a[j + 1] that (a[1] + a[2] + ... + a[j]) / j = a[1] and so on.

Now we must understand how we can efficiently binary search. Let x be value that we want to check. So this inequality should be performed:

(pf[j] — pf[i — 1]) >= x * (j — (i — 1))

Where pf[i] = a[1] + a[2] + ... + a[i] This can be represented as:

pf[j] — x * j >= pf[i — 1] — x * (i — 1)

Left part nothing else than line equation. So we can store lower CHT. When we check x for corectness we should also binary search for line at CHT that contains x.

Thus we achieve complexity O(n * log n * (log 10^6 * ε ^ -1)) where ε is needed precision.

But this solution will get TL. So we need further optimizations.

Note that answer is non-decreasing sequence. So needed x only increase. We can use pointer technique for searching line at CHT that contains needed x and than binary search at some interval.

Thus we achieve complexity O(n log (10^6 * ε ^ -1)).

This is my solution https://codeforces.com/contest/1299/submission/70688494.

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

    I'm interested in your approach. Could you tell me what is CHT?

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

    Really fascinating !!. But there is a question I want to ask:

    In your code, I saw this :

    for (int it = 0; it < 60; it++){
                ld md = (l + r) / 2.0;
                int ps = st;
                ld bas = ld(pf[i - 1]) - (ld(i) - 1.0) * md;
     
                if (ld(K[ps]) * md + ld(B[ps]) - bas >= E)
                    l = md;
                else r = md;
            }
    

    So this is where you binary search for the minimum answer x. But $$$ps$$$ seem to remain the same during this loop (equal to $$$st$$$). So you always work with line $$$K[st] * X + B[st]$$$ with every $$$x$$$ from 1.0 to 1e6. I have just learned CHT and I think each line should hold the max/min in an only interval, so different $$$x$$$ will have the max/min in different intervals, right.?

    Could you clarify this please? Thanks so much.

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

      Yes, each line should hold the max/min in an only interval. But I search for needed interval (such interval where our x lays) with pointer technique and when I found it I start binary searching.

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

        So every x from 1.0 to 1e6 get max/min at that same line? Am I missing something?

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

          No. To this interval belongs only values from [fr[st], fr[st + 1]) (or from [fr[st], +oo) if our line is last). But it makes no difference because value more than right bound we can't achieve (I think it's clear) and value smaller than left bound we can't achieve (because optimal value belongs to other interval that doesn't fit (we check this while moving the pointer)).

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

            Thanks so much! I understood it. And actually we don't need to binary search for x at all. x is the x value of cross point for line -(i — 1) * X + pf[i — 1] and line K[st] * X + B[st]. I test this with your solution and get accepted. Link

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

About 2E/1C, there is an arguably simpler "greedy" solution using a stack in $$$O(n)$$$

The stack algorithm

Here is my implementation 70666728

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

    Awesome!

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

    it is TLE with py3

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

      Not really. This problem is heavily IO bound, and in Python3 a lot of that stuff is slower because they changed to using unicode strings (I'm using Python2 just to easily get around that). But there are ways to make Python3 fast as well.

      For example I took your code and added my fastIO template to it 70718663, and now it runs in 1887 ms.

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

    Isn't it more or less equivalent to the editorial solution? Since this is basically how you find the convex hull anyway.

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

      Hahaha, it definitely is xD. These 78 upvotes and "Awesome!" comments xDD

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

      As stated in the editorial, the solution to the problem is a lower convex hull. So any algorithm solving this problem will find a convex hull, and in particular this stack algorithm can be interpreted as creating a convex hull.

      However I would argue that it is possible to get an intuitive understanding of the stack algorithm without thinking about it as finding a convex hull. It's this intuitive understanding that I'm trying to highlight.

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

    One stupid question, is it always possible that any problem that has solution using CHT,can also be solved by stack,if yes or no what is the reason.Thanks in advance.

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

    Awesome, Helped a lot !!!

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

i couldn't find 'so mean' and 'around the world' problems during the contest. what are these problems and why are they in the editorial

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

Thanks for the useful tutorial <3

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

Does anyone have a submission to div2E / div1C that runs in time on C++11?

I swear I'm so pressed rn:

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

    By far the majority of the runtime comes from the IO. For example see 70688591 by neal running in 249 ms. He has a custom template for printing doubles. Narut tested to remove neal's fast IO template in 70694340 and now it runs in 1902 ms.

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

    As pajenegod mentioned problem here is IO. Try changing cin/cout. I'm sure printf/scanf with c++11 runs faster. E.g. -
    Printf/Scanf gets ac whereas same soln got tle on cin/cout

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

    Checking for central-symmetry is equivalent to checking if each pair of opposite sides are equal and parallel. You can do this easily using integers only: no doubles needed.

    Check my code here: 71015952

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

      HINT: To prove that central symmetry is equivalent to opposite sides being equal and parallel, we can use congruence of triangles.

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

C could be solved by repeating the greedy We are going to keep track of the segment sum, and size Make N 1-lengthed segments. Starting from an element, make a new segment by adding elements. If the element is bigger than average, stop and make a new segment. If we complete whole thing, do this again from the newly formed segment array. If it doesn't change, print it. It looks like N^2, but it somehow passes.

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

Isn't it the case that the isosceles trapezium after joining accordingly will make a hexagon but is following the property of symmetric around the center. ( Div 2 : D, Aerodynamic)

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

    Isosceles trapezium does not have central symmetry. A central symmetry is when a line passing through the center of symmetry has equal length on both sides of the polygon.

    For you case

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

i understood a|b-b is equivalent to a&-b but then what we have to do. i was unable to understand editorial. Can anyone explain me in detail. Thanks in advance.

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

    Consider 4 no.s : a b c d , Now, f(x,y) = x&~y

    The question requires: f(f(f(a,b),c),d) which is essentially val = a&~b&~c&~d.

    Notice that you have to maximize val by positioning any element at first position and remaining at any position after and for that,
    you can iterate and for any element i find ~a[0]&~a[1]...&a[i-1] & a[i] & ~a[i+1]...&~a[n-1].

    Find when this value is maximized and put the element at i at front. That's your answer

    Sample submission : Jiangly

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

      thanks a lot for this clear explanation. it always helps a lot for beginners like us

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

      for array 9 1 2 5 the output of Jiangly this code is 9 1 2 5 which has function value 8 .. but isn't maximum function value 9 is possible with array reordered as 5 1 2 9 ?

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

        5 1 2 9 gives 4 tho (Think of it like the value cannot be bigger than a[0] because of & property)

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

I don't know the problem of my code.

Help me, please.thanks.

The problem is RUNTIME_ERROR.

https://codeforces.com/contest/1300/submission/70701084

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

I have a DP solution for 1C .

dp[i].FIR means the smallest average number of an array ai~ar (i<=r<=n)

dp[i].SEC=r

now we can update the dp in "O(n^2)" ,LIKE THIS:

for(i=1;i<=n;i++)
	for(j=i;j<=n;j++)
	      if(dp[j+1].FIR<(sum[j]-sum[i-1])/(j-i+1)){
			/* sum[i]-> Prefix Sum */
			j=dp[j+1].SEC;
			continue;
}

then if we know the smallest prefix average number from each position.The problem become much easier!

We just need to perform the operations from left to right by "Greedy".

You can also see my code in my "submissions".

Although it is like an algorithm of O(n^2),but in fact it is very fast.

Update it is O(n)

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

EDIT: Actually, never mind.

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

    Your argument proves that for any $$$(x_0, y_0)$$$ in $$$T$$$ you can embed the vector $$$\left(\frac{x_0}{2}, \frac{y_0}{2}\right)$$$ inside $$$P$$$. It doesn't prove that the point $$$\left(\frac{x_0}{2}, \frac{y_0}{2}\right)$$$ actually lies inside $$$P$$$, which is what you really need. And this is false in the general case, so your proof has to somehow involve $$$P$$$ being centrally symmetric.

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

Для проверки того, что выпуклый многоугольник центрально-симметричен, достаточно проверить, что противоположные стороны параллельны. Доказывается через проведение прямой, параллельной рассматриваемой стороне, яерез центр симметрии. Это немного проще, чем пересекать прямые, соединяющие противопложные точки. Так как точки целочислены, то проверять параллельность можно в целых числах.

UPD. Необходима не только параллельность каждой пары противоположных сторон, но еще и равенство их длин.

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

    Дядя Петя, ты дурак? Возьми правильный шестиугольник и параллельно сдвинь одну сторону, не меняя направления других сторон, он не будет центрально симметричен, хотя стороны всё ещё параллельны

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

      Я думаю, что он забыл добавить, что заодно с параллельностью проверить равенство противоположных сторон, т.е. просто равенство векторов.

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

      Можно рисунок параллельно сдвинутой стороны в правильном шестиугольнике? Ну или 6 точек как контр-пример.

      UPD. Понял, необходима не только параллельность каждой пары противоположных сторон, но еще и равенство их длин.

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

    пересекать прямые

    А ничего, что пересечения должны быть в серединах отрезков? Так что даже не надо писать код для пересечения прямых

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

I think Dishwashers should never prepare contests again

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

Div1D definitely should have been posed without this stupid condition about no cycle passing through 1 of length >3. It can be solved as noted by tfg here: https://codeforces.com/blog/entry/73664?#comment-579444 (that's not the best description, but it can be made working). First thing is that this condition is super ugly and unnatural so that it would be much nicer without it and second thing is that finally there would be something to think about in this problem making it significantly more interesting to solve as well.

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

    Sorry mr grandmaster but I don't understand tfg's solution

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

      Yeah, I understand this description might be quite cryptic, so let me explain how I think of this (or should I say "sorry ms grandmaster, I should have expected this"?)

      Delete 1 and for every connected component calculate subspace spanned by cycles in it. Now let's focus on adding edges to one of these connected components and then merge partial results (which are mappings from 374 subspaces to number of ways we can get them in this particular component) to get overall one. This merging introduces *374 overhead to complexity, but that's not something huge (and actually for smaller components we will not get all 374 possibilities, so it will be significantly less in practice).

      So how to solve it for one particular components with some edges from 1 added to it? For a fixed component we divide edges into ones from spanning tree and ones outside of it (each such gives one vector to basis). Let's assume we fix our favourite edge from 1 to that component and add it to spanning tree. Every following edge that we decide to add from 1 we treat as non-tree one and it gives us one cycle whose cost we are able to calculate and add it to the subspaces dp. So we are able to solve it if we add *n to complexity by fixing first added edge. Key observation here is that edges actually can be partitioned into 32 equivalence classes. Instead of calculating cost of the cycle directly we can fix some favourite vertex in that component r and calculate cost of new cycle as xor of costs of paths from 1 to r using first added edge and from 1 to r using new added edge. There are only 32 possibilities for cost of path from 1 to r using first added edge what adds *32 factor to complexity for particular component.

      Overall complexity for original problem was $$$O(374n)$$$ while now it is $$$O(374 \cdot 32 \cdot n + 374 \cdot 374 \cdot n)$$$, where first part comes from dp for each component and second one comes from merging results from different components (and that part should be actually significantly faster).

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

        Understood, thanks. It's sad that this possibility is wasted

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

        Actually that's not exactly what I had in mind, you can have dp with states [i-th edge][current subspace][height of the first edge you've chosen in the current connected component or if you haven't chosen it yet]. This way it's actually O(374 * 32 * N) because you don't have an O(374) transition to merge stuff, just an O(1) transition but with an additional state.

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

        Sorry but I have a problem about Div1.D that how to caculate the number of subspaces?

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

    The most challenging part is the edges between nodes which are connected to 1; I don't know how for each subspace count the number of ways to delete edges adjacent to 1 such that remaining edges form this subspace

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

Hello in 1299B, how can i avoid precision errors checking whether the midpoints of segments connecting the opposite vertexes coincide? I am receiving WA test 53

https://codeforces.com/contest/1299/submission/70740871

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

Can someone pls explain the solution to aerodynamic? I couldnt quite get it asto why a figurewith central symmetry would be an ans.

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

Not sure if anyone discussed it already, but I find the following solution for problem E (Div 2) easier and more intuitive. It is based on the fact that if the prefix is computed optimally, when you are at position i, all you have to do is to iterate from i to 1 (lets say using j) and see if you can obtain a better solution by applying the operation on the segment [j, i]. If you can, then move j, if not, then stop (since prefix is optimal, it means that it is sorted, so you dont need to check smaller indexes since they also have smaller values). Now this is just a brute force, but it can be optimized by representing a subsequence having the same value as a pair of (sum, number of elements). So you end up with O(n) complexity. 70909016

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

Here how I solved Div 1 B - Aerodynamic (Div 2 D) in contest:

Step 1: Use GeoGebra to plot test 3 and realized that the opposite sides are parallel.

Step 2: Go back to the statement and realized that it's also true for test 1.

Step 3: "Coincidence? Nah, I don't think so. Let's code it"

My submission: 70663347.

I still don't know how to prove it. Could someone help me?

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

In 1300C - Anu Has a Function i have used this:-

ll a1=-1;
for(int i=32;i>=0;i--)
{
	int count=0;
	int index=-1;
	for(int j=0;j<n;j++)
	{
		if(a[j]&(1<<i)==1)
		{
		count++;
		index=j;
		}
	}
	if(count==1)
	{
		a1=index;
		break;
	}
}

what will happen if we are unable to find a1? How to take a1 for the solution ?

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

My approach to C:-

If any bit occurs more than 1 times in the array then it will always be 0 in the final answer so we just need to take in account the bits having count 1 in each number and then sort in descending order each number according to this new value..

My submission 86092229

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

    thanks for the easier explainantion

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

    you are doing this to check the jth bit
    and it works for(i=0;i<n;i++) { cin>>a[i]; x=a[i]; for(j=0;j<32;j++) p[j]+=(x>>j&1); }

    can you please explain why for(i=0;i<n;i++) { cin>>a[i]; x=a[i]; for(j=0;j<32;j++) p[j]+=(1LL<<j)&x; } this code of mine is failing ![user:dhananjay_049]

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

      The statement p[j]+=(1LL<<j)&x means

      shift 1 j bits to the left and then if x also has jth bit set then add 2^j to the p[j]. but here you only need to check if jth bit is set or not .

      you can make your code work by just adding a conditional operator like this.

      p[j]+=( (1LL<<j)&x ? 1 :0)

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

Here is a much easier solution for C.

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

I have gone through all comments/editorial for Problem C(div 2)/ Problem A (div 1). But Not able to understand it completely. Can anyone please explain it in more detail.

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

What does Z(2,5) mean? (Problem D)