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

Автор dreamoon_love_AA, история, 5 лет назад, По-английски
Tutorial is loading...
author's code:
Tutorial is loading...
author's code
Tutorial is loading...
author's code
Tutorial is loading...

UPD: onthefloor provides proof for what I mention here.

author's code
Tutorial is loading...

a super simple solution which is differet to this blog provided by Swistakk.

author's code (from bottom to top with min heap)
isaf27's code(from bottom to top with sorted array)
author's code (from top to bottom)
Tutorial is loading...
author's code
Tutorial is loading...
isaf27's solution
author's solution
  • Проголосовать: нравится
  • +116
  • Проголосовать: не нравится

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

Check out the video editorials

Also, you should add the codes under spoiler dreamoon_love_AA

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

Auto comment: topic has been updated by dreamoon_love_AA (previous revision, new revision, compare).

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

I had different approach for Div2B, which is probably more intuitive.

Lets calculate two values:

$$$rpref[i]$$$ — the number of different elemtens in ith prefix.

$$$rsuf[i]$$$ — the number of different elements in ith suffix.

So lets fix l1. Our task is to check that sequences from [1 to l1] and from [l1 + 1 to n] are permutations. How to check this?

Sequence from [1 to K] is permutation if and only if sum(1..k) = k * (k + 1) / 2 and rpref[k] = k. We can do same procedure for suffixes.

My submission: https://codeforces.net/contest/1330/submission/75366634.

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

Nice contest, D1B is beautiful!

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

    Thank you for the explanations! I could not understand Div2C.

    Regarding your solution for Div2C, the inner while loop was not required

    for(int i = m;i >= 1; --i){
        	// cout << ans[i - 1] << ' ' << a[i - 1] << '\n';
        	while((ans[i - 1] + a[i - 1] - 1) < pos_needed) ++ans[i - 1];
        	pos_needed = ans[i - 1] - 1;	
        }
    

    Instead of jumping one step ahead until you find a roadblock, you can simply take the starting point of the next block (whose value had already been calculated), and decrease one. Say it's last = ans[i+1]-1. So if this last value is greater than the end point of the current segment, then we can simply shift the current segment to the last point. If last is less than our endpoint, then we just update last=ans[i]-1, and move on.

    Due to this, a tad bit faster solution can be found.

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

Amazing contest.

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

Somebody explain Div2D in smaller steps?

I understand that we need to choose a[i] in a way that we add at least one bit to b[i-1], and we can remove all lower bits. How does this lead to closed formular for fixed a[0], or sum of "some" a[]s?

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

    Suppose x is some element of our sequence (say at index u). Suppose the i-th bit of x is set . Now if for every other element of the sequence, the i-th bit is 0, the prefix xor array(considering i-th bit only) will be 0 till (u — 1) and 1 after. If there exist some other element (say at index v) with i-th bit set, then the prefix xor array will be 0 till u — 1, 1 from u to v — 1 and 0 after v. This violates the strictly increasing property of prefix xor array. Hence there should be a unique element with a particular bit set. Now since a(i) > a(i — 1) and a(i) and a(i — 1) do not share any common bit, MSB(a(i)) > MSB(a(i — 1)).

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

i can not understand div2 C problem correctly. can anyone help me in this plzz. the editorial is quite fast.

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

    li in i-th operation means in this operation, you can color li numbers of cells, you can start with any position as long as there are no less than li cells after this position and cells will have the color from the latest operation. So the task is to find the starting position for every operation so that you can color all cells and every colors are used at least once.

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

    You can see the tutorial one more time. I add some detail about this problem.

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

      I have some issue in understanding problem Div2-C

      In test case 2 2 1 2

      n = 2 m = 2

      output should be 2 1

      Why is it "-1"?

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

        In your solution, the first color will be covered by the second color. In the end, there is only one color.

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

I loved the contest. Thank you dreamoon_love_AA

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

Can anyone tell what was wrong with this submission? https://codeforces.net/contest/1330/submission/75383926

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

    for input like 1 2 1 2 3 4 ans is 2 4 from both ways by your code and each ans should be unique

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

Thanks for the wonderful tutorial,Ienjoy this competition very much ^_^

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

I liked the contest very much, but I wish the pretests can be better next time.

Thank you for the round,and thanks to Denis aramis Shitov.

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

I thick that Div.1B is much more difficult than Div.1C.

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

    Tbh I think it depends on how good you are in counting problems. I found divB easier because I'm not that good in implementing even though I had the algo for div1C

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

Could anyone explain why my 2C is wrong? Thanks! Link: https://codeforces.net/contest/1330/submission/75413150

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

What a great contest!

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

Why "For each i, posi=max(i,n−suffix_sum[i]+1)"?

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

    Same question (about 2C/1A). Seems like magic — can anyone explain the intuition?

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

    One observation is that for any valid solution we can adjust it so that if i<j holds then pos[i]<pos[j] also holds. Thus we can do it greedily. First, we make pos[i]=n-suffix[i]+1 for every i. After doing this, we may find pos[1] < 1. Then we need increase pos[1] to 1 and then increase pos[2] to 2 if pos[2]<2 then increase pos[3] to 3... Iterate this until we find pos[x]>=x.

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

Nice Contest!Good problems.

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

Weak pretests for Div2A unfortunately :(

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

In 1330B — Dreamoon Likes Permutations , according to author solution if we give test case like size of array is 5 and array elements — {1,2,3,4,5}. Then ans is 2 0 5 5 0 But it is said the two permutations are of non-zero length. Isn't this a contradiction? Answer shoud be 0. Please correct me where I am wrong.

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

Could someone please explain how we arrived at this formula for Div 2C? For each $$$i, pos_i=max(i,n−suffixsum[i]+1)$$$.

EDIT: Formatting

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

Problem B(Div2) also solvable by using the prefix sum. Here's my submission: 75458331

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

Problem B can be easily solved using rolling hash!

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

Div2-D/Div1-B, I dont't know how to solve it, but i just print the answer for the first 16 number using a program I. And I found regular pattern in it (table I). i-th row in table I is the number of every possible xor-sum of the case n = i.

Observation I: $$$f(x)$$$ represents the number of the case n=x, then $$$f(x) = f(x-1)*2$$$ if x is qual to lowbit(x) where lowbit(x) means x&-x. The lowbit of 0b100100 is 0b100.

Observation II: $$$g(x)=highbit(x)$$$, highbit means the highest-bit in the number. The highbit of 0b10100 is 0b1000 and the highbit of 0b11101 is 0b10000. Then $$$f(x) = f(x-1) + f(g(x)-1)$$$ if x is not equal to lowbit(x). So $$$f(x) = f(g(x)) + (x - g(x))f(g(x)-1)$$$ if x is not eual to lowbit(x).

Then I write the solution by the observation. Solution in contest

Thanks for the fortune make me become candidate master.

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

Can someone please tell me what is wrong with my submission for Div.2B? Similar idea with editorial but simpler implementation with 2 sorted vectors?

My Submission: https://codeforces.net/contest/1330/submission/75460697

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

Problem D reminded me of Bookshelves. The reason it reminded me of it is because both problems require us to divide the given problem into 30 sub problems (based on the number of bits) and then solve that sub-problem with a DP. When I saw Bookshelves, I was very surprised at the idea. But introspecting about it was the reason I was able to solve this D.

Here are my solutions, in case anybody wants to refer them

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

https://codeforces.net/contest/1330/submission/75403704 Getting wrong answer on B, can someone help?

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

For Div1B sequence can be found on OEIS. This is the differences between answers for $$$d$$$ and $$$d+1$$$. Source code for python available on OEIS too in bottom of the page. I copy-pasted this code to my program and got accepted during contest. Idea to search on OEIS came to me on second hour, because I believed to author when read the statement that it can't be found on OEIS.

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

    I think what you mean is the sequence of "distinct" differences between answers for $$$d$$$ and $$$d+1$$$. You are right. I didn't found it when I test it during preparing the contest. It shows that I still need to train myself about the ability of searching in OEIS. (>__<)

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

In Div2 D, I think there is a typo in the example of editorial. For example, when n = 6 , it should be d=6 . 'n' is the size of a matrix.

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

Love how you explained the constructive algorithm in 1329A so thoroughly! I didn't find a solution in 2 hours, just as you say, the conditions are way too 'open'. Your explanation gives me new insight on how to approach problems like this.

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

dreamoon_love_AA can you please explain it more for coloring problem.

There exists some i such that li+i−1>n. In this condition, at least one of the first i−1 colors will disapear after i-th operation.

how to prove it.

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

    If there exists some $$$i$$$ such that $$$l_i+i-1 > n \Leftrightarrow i > n-l_i+1$$$, the $$$i-th$$$ operation must be done at position $$$p_i < i$$$, that is because $$$p_i \le n-l_i+1 < i$$$. In this case, it will overlap other colors and make them disappear. Hope that help!

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

      i m not satisfied with the tutorial.

      What if the test case is 6 5 1 4 3 4 2

      As per tutorial it gives -1.But still the solution is possible as 1 2 4 2 2 which is possible.

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

        why's that, the 2nd colour and the 4th colour have the same length and the same p[i] (as you said), then the 4th colour will surely overlap the 2nd one. (or did you have a typo i think?)

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

          try to colour as i have mentioned in the answer. There will be one colour of each m which is the requirement in question.

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

    This means that n — li < i — 1. Now, whenever you colour li blocks, exactly n — li blocks remain uncoloured. If this number is less than i — 1, it means that less than i — 1 blocks remain uncoloured after this operation. But in the previous i — 1 operation, you have put i — 1 colour and even if each of them occupies just 1 block, it will disappear after this operation.

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

In Div2 problem B (1330B), i don't understand what "p+len1" mean, can anyone help me? (line 16)

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

In Div2-C, how do we know that after applying "sort" constraint, our problem won't become unsolvable?

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

    No need to sort SEE HERE

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

    You won't know before you try it. That's just like We don't know whether we can solve a problem before we think out a solution. When solving problems, just like do DFS on the thought until you arrive at the correct solutions. apply "sort" constraint is just one possible try on this problem. You can also try many other things such as all $$$p_i$$$ are equal or $$$p_i$$$ is from larger to smaller.

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

Nice contest . This is how contests should be — 5 problems and 2 hrs. max . Nice , compact and standard problem statements and conducted very well . Although I believe pretests should have been stronger . This is my first comment ever and I wrote it to appreciate your commendable work .

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

Was scrolling through the comments and didn't seem to find someone giving a proof on the correctness of Div 1B/Div 2D (that is, the sequence is valid if and only if $$$h(a_i)<h(a_{i+1})$$$ always holds.

If $$$h(a_i)<h(a_{i+1})$$$ always holds, then $$$a_i<a_{i+1}$$$ for for each $$$i$$$ so the first condition is true. To show that this would imply $$$b_i<b_{i+1}$$$, for each $$$i$$$, $$$h(a_k)<h(a_{i+1})$$$ for all $$$k\le i$$$. It then follows that $$$h(b_k)<h(a_{i+1})$$$ for all $$$k\le i$$$ (by the definition of XOR), and therefore $$$h(b_{i+1})=h(a_{i+1})>h(b_k)$$$ for all $$$k\le i$$$: the first equality is because $$$b_{i+1}=a_{i+1} \otimes b_{i}$$$. It then follows that $$$b_i$$$ is also increasing.

Now we show that $$$h(a_i)<h(a_{i+1})$$$ is essential. Suppose otherwise. Given that $$$a_i$$$ is increasing, there exists $$$k$$$ satisfying $$$h(a_k)=h(a_{k+1})$$$. Choose such a minimum $$$k$$$ (i.e. $$$h(a_i)<h(a_{i+1})$$$ for all $$$i<k$$$); adapting the proof above we see that $$$h(b_k)=h(a_k)=h(a_{k+1})$$$, which means that the $$$j$$$-th digit of $$$b_k$$$ and $$$a_{k+1}$$$ in their binary expansion matches for all $$$j\ge h(b_k)$$$. It follows that $$$b_{k+1}=a_{k+1} \otimes b_k$$$ must have the $$$j$$$-th digit as 0 for all $$$j\ge h(b_k)$$$, which follows that $$$h(b_{k+1})<h(b_k)$$$ and therefore $$$b_{k+1}<b_k$$$, contradiction.

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

    Why do in the final answer , we are subtracting the value obtained by -1, like I understand how we got 24 in the editorial solution but why do we subtract the value obtained by multiplication by 1 to get 23 ? Plz help.

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

      The empty sequence is counted once in the analysis, but it's not allowed. Hence the $$$-1$$$.

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

1329B - Dreamoon Likes Sequences Can someone please explain how does knowing v=0,1,2 ... solve the problem for all lengths n>=1 ?? Thanks.

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

dreamoon_love_AA May I know when will the construction of Div. 1 C and E be over? I am eagerly waiting for the editorial of Div. 1 C or may I get some hint for Div. 1 C?

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

Auto comment: topic has been updated by dreamoon_love_AA (previous revision, new revision, compare).

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

My code for div 2B was O(n^2). It gave TLE on test case 3. But according to the constraints it should have worked. Please help me out if I am missing something. https://codeforces.net/contest/1330/submission/75401692

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

    Why do you think it can work with the constraints? $$$O(n^2)$$$ shouldn't work.

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

      n=200000 n^2=4*10^10 t=10^4 In 1 second we can do 10^8 operations Constraint is 2 seconds. Hence we can do 10^16 operations. t*n^2=4*10^14. So I thought it should work. I think I am wrong somewhere. Please correct me.

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

Anyone explain properly in simple language Div 2C.

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

Auto comment: topic has been updated by dreamoon_love_AA (previous revision, new revision, compare).

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

In div1.c bottom to top approach, while constructing the solution, it is said if the current value at the iterated node is not in final tree call f(). But how to prove its possible to do the operation at that node without the leaf going below height g?

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

    I had written it. Please see the tutorial carefully.

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

      I didn't understand this part, "Then We iterate node from smallest index to the larger one. We always can determine the weight value of the iterated node, because the weight value only can be the maximum value in its subtree". Didn't we already determine value for each node while finding minimum sum?

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

        When we have chosen the weight values set $$$S$$$ remaining in the final tree, according to the trait of max heap, the value of node $$$1$$$ must be the largest one from $$$S$$$. And the value of node $$$2$$$ must be the maximum value in the subtree of node 2 who belongs to $$$S$$$ except the final value of node $$$1$$$. And so on, we can make sure all values in the final tree will be the same with the lower bound calculated by the algorithm.

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

The more I hear/read about poeple's solutions to Div1C, the more I appreciate my strikingly simple solution. All authors solutions seem to me overly complicated. I call positions from $$$1$$$ to $$$2^g-1$$$ free initially (positions that are at least $$$2^g$$$ are not considered free). I sort all elements in this heap and consider them in increasing order. Whenever I consider some value, I traverse path from its initial node to root. If there is no free element on it, I skip it. If there is one, I check whether both of its sons are not free, and if it the case then I put it there and call it taken instead of free (if exactly one of sons is free then I skip it). And that's it, very short code here: https://ideone.com/1XiSlu

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

    Wow! I appreciate your solution a lot!

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

    I tried to understand the correctness of your simple solution, but couldn't.

    Could you please kindly provide some proof of it? or at least any hint?

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

      Lemma: A height-$$$g$$$ heap is a valid final heap if and only if for every position $$$r$$$, the element $$$a_r$$$ on it is originally in the subheap rooted at $$$r$$$. Proof: =>: observe that an element can only move to the position of its ancestor <=: observe that if you fix the elements left in the final heap, the shape of the final heap is unique. (largest element should be the root, and right and left subheap both have unique shape by induction hypothesis)

      We will prove by induction that

      1. If we place an element, it is in the correct position.

      2. If we skip an element, it is not in the optimal solution.

      Proof for 1. Suppose we can $$$a_r$$$ on $$$r$$$ but in the optimal solution there's $$$b_r$$$ on $$$r$$$. If $$$b_r>a_r$$$, we can replace $$$b_r$$$ with $$$a_r$$$ in the optimal solution. This is still valid by our lemma, and has a better value (contradiction). If $$$b_r<a_r$$$, that means we skip $$$b_r$$$ before. (contradiction)

      Proof for 2. Suppose we skip $$$a_r$$$ but it's actually on $$$r$$$ in the optimal solution. Now consider all elements under $$$r$$$ in the optimal solution. They are $$$<a_r$$$ so we should have placed them in the correct position. That means all nodes under $$$r$$$ are full at this point so we will not skip $$$a_r$$$ by our rule. (contradiction)

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

    Thanks for the great and easy solution.

    I had one doubt and would be grateful if you could take 5 minutes to clear it out.

    How did you decide that the nodes not considered from the sorted array will be the one that we have to choose while doing f operation?

    TIA

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

div2D min(2(v+1)−1,d)−2v+2.why added 2 here.anyone help please

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

    $$$\min(2(v+1)−1,d)−2v+2$$$ mean the number of different condition that you can choose at most one number from $$$2v$$$ to $$$\min(2(v+1)−1,d)$$$. Let $$$x = 2v$$$, $$$y = \min(2(v+1)−1,d)$$$. Firstly, there are $$$y-x+1$$$ numbers from $$$x$$$ to $$$y$$$. So if you choose exactly one number, there are $$$y-x+1$$$ choices. Secondly, you must add an additional one for the case don't choose any number from the range. That's why.

    UPD: fixed the bug in the fomula

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

      Thanks for explaining this point, but I think that y = min(2(v+1)-1,d) without -2v + 2.

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

      Why do in the final answer , we are subtracting the value obtained by -1, like I understand how we got 24 in the editorial solution but why do we subtract the value obtained by multiplication by 1 to get 23 ? Plz help.

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

Auto comment: topic has been updated by dreamoon_love_AA (previous revision, new revision, compare).

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

Div2D For example, when d = 6, there are 2 choices for v=0, 3 choices for v=1, 4 choices for v=2.

Please someone give me all the choices for every v. Because I get it like that for v = 0 --> 1 choice : 1(1) for v = 1 --> 2 choices : 2,3(10,11) for v = 2 --> 3 choices : 4,5,6(100,101,110)

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

I was wondering if anyone could let me know what the issue with this code for problem C Div 2 is (and possibly a test case to replicate it). Running on C — Dreamoon Likes Coloring gets the wrong answer on test case 6, but the input is too long to replicate and copy. I have also tried similar types of values to this test case, but they all succeed. I do know that my answer outputs "-1" when it should be possible. I appreciate it a lot! (First time posting.)

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Scanner;

public class C {
    public static void main(String[] args) throws IOException {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int m = std.nextInt();
        if (m==1) {
            if (n == m) {
                System.out.println(1);
            } else {
                System.out.println(-1);
            }
            return;
        }
        BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
        int tmpN = n;
        int[] arr = new int[m];
        for (int i = 0; i < m; i++) {
            arr[i] = std.nextInt();
        }
        int[] postSum = new int[m];
        postSum[m-1] = arr[m-1];
        for (int i = m-2; i>=0; i--) {
            postSum[i] = arr[i] + postSum[i+1];
        }

        int lastBlockStart = n - arr[0] + 1;
        int lastBlockEnd = n;
        log.write(lastBlockStart + " ");
        //inclusive...
        for (int i = 1; i < m - 1; i++) {
            int greedyStart = (lastBlockEnd - 1) - arr[i] + 1; //place at this index if possible
            int greedyStart2 = postSum[i + 1] + 1; //must place at this index in worse case...
            int currBlockStart = Math.min(greedyStart, greedyStart2);
            int currBlockEnd = currBlockStart + arr[i] - 1; //ends here...

            if (currBlockEnd < lastBlockEnd && currBlockEnd + 1 >= lastBlockStart) {
                lastBlockEnd = currBlockEnd;
                lastBlockStart = currBlockStart;
                log.write(currBlockStart + " ");
            } else {
                System.out.println(-1);
                return;
            }

        }
        int currBlockStart = 1; //starts here
        int currBlockEnd = currBlockStart + arr[m - 1] - 1; //ends here

        if (currBlockEnd < lastBlockEnd && currBlockEnd + 1 >= lastBlockStart) {
            log.write("1");
        } else {
            System.out.println(-1);
            return;
        }
        log.flush();

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

Wow dreamoon_love_AA, This editorial includes, How to approach the problems, Not just solution. Kudos to You, Thank You!.

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

Can anyone provide proof of that is stated in Div2(Problem D) editorial about h(ai) must less than h(ai+1).

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

    I had provided the link of the proof written by a good person in the tutorial. Please see the tutorial carefully.

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

for Div1-C i have an idea to solve it. for each node find the number of node we have to delete in its subtree from left side, since the number of node need to delete from right and left side will be equal to get perfect binary tree after all operation, lets denote it by num[i]. and maintain left[i] and right[i] to store number of nodes we have deleted in left & right subtree of node i till now respectively. now if i call required function from pos 1 then there are 4 possiblity.

if(v[l]>v[r] && left[i]<num[i]) then it will goto left child

if(v[l]>v[r] && left[i]==num[i]) then it has to go to right child in this case i will update the pos from where i am calling function to get perfect binary tree finally. similarly other two condition where v[r]>v[l].

once it get to leaf node, i will break it and call required function from pos that we get from above function. As i am calling required function from top most possible node every time then i should get minimum possible total sum and and i will also get binary tree finally. But i am getting WA and i couldn't find such test case. Here is my submission. Can anyone tell me what is wrong in my solution

Update: thanks dreamoon_love_AA i forgot to update left[i] & right[i] for all ancestor of node from where i was calling required function. If some one want to look, here it is

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

https://codeforces.net/contest/1330/submission/75732591

i Dont't know that is wrong logic in my code can some one help me with div2 B problem will be much appreciated thanks

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

I do not understand the editorial for Div2C. Can someone explain it better?

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

    There are many tutorials you can search from google or in Codeforces comments(For example, here). Please see them first. I'm busy on weekdays. I will add it in the weekend.

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

I've been trying div2 (B. Dreamoon Likes Permutations) but I'm not really sure why am I getting T.L.E could you please help me to find out ? 78243837 ... I find the maximum inside input array and check the two possible casses (len1 = ma, len2 = n- ma ... len1 = n-ma, len2 = ma)... I use a function that is intended to check if there is a permutation in the subarray bounded by the different lengths in O(n)

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

My approach for div 2 B is little diff. i stored elements of the prefix and suffix in 2set and checked if size of set is equal to size of suffix . this will ensure that the elements are unique and also the max element should be equal to the length. though sometimes it gave segmentation fault when i tried to remove elements from the suffix set.

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

I don't get why can we use $$$p_i = \max(i, n - suffix\text{_}sum[i] + 1)$$$. If you don't describe the most crucial part of the solution what's the point of the editorial?

The editorial for Div2C has so many typos and odd english that it seems like a first draft.

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

    Sorry, I'm the guy rejected by Google and many companies because of bad English. It' quite hard to write a better editorial of this problem in English for me. And I recommend you to find tutorials from the Internet. There are many better editorials in the Internet nowadays. So I won't update this tutorial anymore.

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

I have a rather "simple to think" solution for Div1 C, This may be a bit long in implementation than the one mentioned by Swistakk, but it is just Greedy and Brute forces, which makes it simple to think in the first place (and so not a 2400 Problem ;).

See my submission — 111844109

Note that this (not as advised by the problem creator dreamoon_love_AA) a top-down approach :)

What basically this does is check if the largest element can be removed from the heap and if it can be removed just remove it (Greedy).

Thus if iterate over the nodes in decreasing value of the node, and if they can be removed from the heap remove them and update the heap as in problem (Brute Force).

To check if it can be removed we will check the sum of height and depth of the node should be greater than "g".

Also while updating the heap we keep an account of the new index of the nodes in a global array "Index".

To me, this seemed easier than most of the solutions I have seen, do tell me if there are some mistakes with the logic :)