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

Автор ch_egor, 3 года назад, По-английски

Thanks for the participation!

1863A - Channel was authored by Endagorion and prepared by irkstepanov

1863B - Split Sort was authored by Endagorion and prepared by ch_egor

1863C - MEX Repetition was authored by Endagorion and prepared by amethyst0

1863D - Two-Colored Dominoes was authored by Endagorion and prepared by AndreySergunin

1863E - Speedrun was authored by Endagorion and prepared by Golovanov399

1863F - Divide, XOR, and Conquer was authored by Endagorion and prepared by ch_egor

1863G - Swaps was authored by Endagorion and prepared by zemen

1863H - Goldberg Machine 3 was authored by Endagorion and prepared by Endagorion, irkstepanov

1863I - Redundant Routes was authored by Endagorion and prepared by Endagorion, irkstepanov

1863A - Channel

Solution

1863B - Split Sort

Solution

1863C - MEX Repetition

Solution

1863D - Two-Colored Dominoes

Solution

1863E - Speedrun

Solution

1863F - Divide, XOR, and Conquer

Solution

1863G - Swaps

Solution

1863H - Goldberg Machine 3

Solution

1863I - Redundant Routes

Solution
Разбор задач Pinely Round 2 (Div. 1 + Div. 2)
  • Проголосовать: нравится
  • +216
  • Проголосовать: не нравится

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

thanks for fast editorial

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

what is test 81 in test case 2 in D ?

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

E is a really good problem!! Thanks for fast editorial.

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

Slowforces

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

can't understand editorial of b

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

    take for example a permutation where 2 appears after 3 whereas to make the permutation sorted 2 needs to appear before 3. For this to happen we must choose 2 as our x and perform the operation this will reposition 3 after 2. Hence we do this for all x where x+1 lies before x in the given permutation.

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

      How do you understand the institution, or did you saw any pattern in this? I'm very slow, any suggestions to solve questions related to strings and arrays on competitive platforms, I feel they are tough for beginners like me

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

        My advice is solve more problems,for improving your implementation so you can crack A quickly solve topcode div2 and for constructive problems just keep solving more problems as time goes on ideas will repeat i know it seems like impossible but yes and this way you train your brain to think of different patterns. So as conclusion if you want to have intuition solve problem especially constructive but don't forget about learning other new algorithms and implementing them or using them to solve the problems.You need to find the balance that's it and of course it takes real time to improve so you need to keep hardwork.

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

      The worst case for this will be O(n^2). Won't it give me TLE?

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

      thanks for the help and apologies for the late reply

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

    It says that if the pair of values $$$(k, k+1)$$$ appears inverted in the input permutation, then you need to perform the operation with $$$x = k+1$$$ in order to get rid of that inversion. Now, just note that if you consider all these pairs and perform the operation when needed, starting from $$$k = 2$$$ until $$$ k = n$$$, the permutation will be ordered.

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

    let's start from k = 1 and see if the (k + 1) position comes after the k position we stop when the condition fails and count it as a turn we chose x as the last item that we get, then we pick another k just the last item we didn't get from the previous turn, Each time we write a set of numbers in the correct order as much as we can, So the answer is the number of turns. To do that just count how many pos[i] > pos[i + 1] for all i from 1 to n — 1. It's exactly this problem : Collecting Numbers

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

      thanks for the help and apologies for the late reply split sort and Collecting numbers can be done like this sort the array keeping their index start iterating from i = 2 if(index of i < index i — 1) ans++

      it can further be optimised as number are 1 — n, we can just place the index of x to the index x in sorted array

      thanks suggesting the Collecting Numbers as it made me understand the concept https://cses.fi/paste/17d0c105267da8d76a177b/

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

Video tutorial for problems A&B&C in english: https://youtu.be/X08zbEDtaI8

Thought would be useful to the community

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

really liked D and E. I hope there will be more such great contests!

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

Video Editorial for problem A,B,C,D.

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

how is O(N^2) possible in F with the given constraints on N? also can you provide test case 3? 1863F - Divide, XOR, and Conquer

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

Finally, editorial written not in broken English

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

Can't understand E. explain

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

    Let, firstly, solve simpler problem. Assume starting time is $$$0$$$ (meaning the first imaginary quest which is prerequisite of any other quest was done at day 0, hour 0). Maintain a $$$dp$$$ array, where $$$dp[v]$$$ is the day when the quest $$$v$$$ is completed. It's clear that if the quest has no prerequisite it's $$$dp$$$ value is zero. Otherwise, let $$$u_1,...,u_k$$$ be prerequisites of $$$v$$$, then $$$dp[v] = max(dp[u_i] + f(u_i))$$$ where $$$f(x) = 1$$$ if $$$h[x] \gt h[v]$$$ and $$$f(x) = 0$$$ otherwise. Answer to the problem is maximum value of $$$dp[v] * k + h[v]$$$ (Since we are counting starting time as $$$0$$$ and $$$v$$$'s quest is done after $$$dp[v]$$$ days on $$$h[v]$$$ hours). However, we need to choose optimal starting time and somehow maintain the answer. Notice that optimal starting time is some $$$h[i]$$$, where $$$i$$$'s quest has no prerequisite. Assume $$$v_1,...,v_k$$$ are such quests and WLOG assume $$$h[v_1] \lt = ... \lt = h[v_k]$$$. We will update starting time from $$$0$$$ to $$$h[v_1]$$$, from $$$h[v_1]$$$ to $$$h[v_2]$$$ and so on to $$$h[v_n]$$$. Let assume we are making transition from $$$h[v_i]$$$ to $$$h[v_{i+1}]$$$. So firstly we must update $$$dp[v_{i + 1}]$$$, then we mist update it's children. So we can simple use DFS. Also notice that every quest will be updated only once, so it should pass the time limit.

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

Would someone please help me understand why my submission for E (221172178) giving TLE. According to me, the time complexity of this code should be O(m+n*lgn), since I am traversing through each edge only once while doing DFS.

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

EFG are all excellent problems. Failed to solve F because I mistakenly thought that 1<=n<=1e5.

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

Why for problem E f(x, y) is defined only with y?

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

Thanks for this nice round, and fast editorial!

Here is my advice about the problems:

A
B
C
D
E
F

Also, could you please clarify a bit the second part of the editorial of F please ? Maybe I'm just bad at english but I don't understand what mask_start and mask_end correspond to

Thanks :)

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

    For point $$$i$$$, if the xor of an interval $$$[i, r[$$$ contains a bit of $$$maskStart_i$$$, then it means it is obtainable, since at one point prior, an interval $$$[i, r'[$$$ with $$$r' \gt r$$$ had that bit for most significant bit of the xor. Same for $$$maskEnd_i$$$.

    So you keep these $$$2N$$$ masks as you iterate over subarrays in length non-increasing to know which ones are obtainable.

    By the way I love your profile picture, where is it from ?

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

C can also be solved using binary lifting. Overkill, but if you spot it quickly, you could just a use a template for insta solve Here is my solution

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

In problem E, can ternary search be used for finding the optimal starting point?

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

Hi all, it would really help if you can post some insights/hints for the problems of this contest on https://starlightps.org ! Here's a link to the problems: https://starlightps.org/problems/collection/cf-pinely-2/. This will help us get more data so users can have a platform to:

  • share/discover hints/insights on various problems
  • find similar problems given insights they struggled with.

Check it out if you're interested. Thanks!

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

i think the problem C was very easy especially compared to B too bad i did not read it early.

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

thanks for the exciting tasks, as for me the gap between D and E is too big

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

For problem E, I didn't understand the editorial, and most other solutions seemed to use some form of Dynamic Programming, which seems different from what I did.

I start by calculating the maximal end time when you start questing at the earliest possible time, which is easy to calculate in O(V + E) time using the topological ordering of the DAG. However, this might not be optimal: it can be better to defer some quests to day 2 so we can start later in day 1, without affecting the end time. So I consider all the starting times of quests that have no dependencies. The key is that I update the end times for other quests incrementally, for an overall O(V + E log V) solution.

Submission with a (too many) comments: 221200048

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

    There's no need for that log, that's what I did as well. Your first step is dp, so I don't get why you're talking about others "using some form of DP".

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

    mark me if I am wrong ? What I got from your code is that particular (ith) quest with (0 dependency) can either be done at (h[i] or h[i]+k) hours so after that you are checking effect of (h[i]+k) ending on other quest so , its complexity will be O((number of 0 dependency node)*(ElogV)) how its possible to get accepted , or It is like each quest can be updated one ,if it is then why it is updated once , please explain

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

      I tried to explain that in the last two paragraphs of the comments at the top of the file. It's not immediately obvious, but for each vertex v, we increase end_time[v] at most once, by exactly K. That means it's actually just O(V + E log V) time overall, not O(V + VE log V) as it would otherwise be.

      And tfg pointed out, correctly, that the priority queue is not needed, so instead of O(E log V) it could be something like O(E), but the really important part is that it's not O(VE), which would be much too slow to pass. The difference between O(E) and O(E log V) is relatively small.

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

    Thank you so much. Easy to understand.

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

    without affecting the end time

    I didn't get this part. If any quest from day1 is getting shifted to day2, then the end time will shift accordingly because of it.

    My sol is similar to yours, I shifted quest from day1 to day2 and calculated the ans which is ( max end time observed due to shift — starting time at day 1 while iterating)

    Submission.

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

      It has been a while since I wrote that :) I think I meant the time at which we complete the final task, not the time the bumped tasked is completed.

      Even then my writing was a bit inaccurate because, as you mentioned, bumping a task without dependencies from day 1 to day 2 can change the final end time, but it's all about minimizing (end time — start time).

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

It is the greatest contest I have ever seen

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

How to solve D if you must colour all cells, not only the domino ones?

»
3 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится +29 Проголосовать: не нравится
Why I didn’t solve F
  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Here's my wrong idea on F: (maybe it's right, I don't know)

    Let $$$s(l,r)=a_l\oplus a_{l+1}\oplus\dots\oplus a_r$$$.

    First let's reverse the operations. Instead of changing subarray $$$[1,n]$$$ into $$$[i,i]$$$, we try to expand $$$[i,i]$$$ into $$$[1,n]$$$. For a subarray $$$[l,r]$$$, we need to find an adjacent subarray (either $$$[r+1,x]$$$ or $$$[x,l-1]$$$) which has a smaller $$$xor$$$ value than $$$s(l,r)$$$, and merge them.

    Let's look at the maximum most significant bit of all $$$a_i$$$. Let $$$cnt$$$ be the number of $$$a_i$$$ s that have this bit. Let $$$b_1,b_2,\dots,b_{cnt}$$$ be all $$$i$$$ that $$$a_i$$$ has this bit.

    If $$$cnt$$$ is odd, then only $$$b_1,b_3,\dots,b_{cnt}$$$ are valid.

    If $$$cnt$$$ is even, then all $$$i\in[b_{2k-1}+1,b_{2k}-1]$$$ are invalid. We can merge all $$$a_{b_{2k-1}}\ \ ,a_{b_{2k-1}\ \ +1},\dots,a_{b_{2k}}$$$ into one number, which is $$$s(b_{2k-1},b_{2k})$$$. Then, the maximum most significant bit is gone and we go on to solve the problem for a smaller bit. What I still can't figure out is how to solve for $$$a_{b_i}$$$. Maybe it could be solved using Segment Tree.

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

I love F very much.Hope there will be more problems like this.

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

https://mirror.codeforces.com/contest/1863/submission/221150801

Can I ask? Why my 7th test got a negative number? I didn't see any "out range" in my variety (for example, when I'm finding the missing number, I'm using long long)

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

is there any other solutions to f?

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

Can someone explain F more clearly?

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

what is test 72 in test case 2 in D?

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

Can someone help me with P5? My idea was to perform a dfs to find pairs (s1,s2) of optimal start time and end time for each component of the directed graph. If d is the number of connected components in the graph, then we will have d such (s1,s2) pairs. Then, I sorted this vector of pairs and found the optimal time.

Issue is I am getting TLE on test case 18. I don't see which operation is being so expensive. Any help will be highly appreciated.

Source Code

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

What is test 72 in test case 2 of D

Getting wrong answer for that https://mirror.codeforces.com/contest/1863/submission/221170325

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

In problem E can anybody help me understand why every node's time is going to be updated at most once ??

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

How difficult are the H and I questions? How come no one has worked them out during the contest... Including our dear Tourist, Radewoosh, JiangLY and so on...

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

I just want to ask what happens if the number in the array provided is not in 0 to n as it is obvious that it wil come in 0 to n+1 with leaving the last element but how can a person do that question because in c it is already given it is in 0 to n So what wil be the difficulty of the above with the present C?

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

In problem C, let n=1,k=1,arr={3} then MEX would result " -2 according to code " but in question its states that mex cannot be negative. Please justify.

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

In the solution of problem F,should the condition be $$$s & mask_start_l \gt 0$$$ or $$$s & mask_start_r \gt 0$$$

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

In the solution of problem F,should the condition be s & mask\_start_l > 0 or s & mask\_start_r > 0

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

Endagorion, big thanks to you for enchanting problemset!

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

Can someone help with the proof/intuition of D? Why can we color the dominoes in any order? I thought that coloring the dominoes according to a row/column might affect the other rows/columns.

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

I tried to implement my solution in E problem but it was giving TLE on testcase 5. please can someone show the mistakes in my code.
my submission: link

Here I have tried to explain my logic:
1. sorted the given array of time at which quest will start and then mapped the indexes accordingly.
2. made an array ind to store indegree of every node of the graph.
3. then calculated the time needed if we start from each node with 0 indegree(as it can be started independently), using calc function.
x = no. of nodes with 0 indegree.
idx: contains the index of node with 0 indegree.
val: contains the time needed to complete the quest if we start from here (to complete all the quests that are dependent on the particular node).
4. used some prefix, suffix logic to get the final ans. (to decide at which point to start)

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

I didn't get most of the edi, but I think that I is much easier (and I upsolved it this way):

I've stopped reading after getting to the point that we will take whole classes of adjacent paths. So let's connect them and make a directed edge from class of shorter paths to a class of longer paths if they contradict with each other. There surely is a way to extend one of the shorter paths into one of the longer paths if this is the case. So we might as well only use edges from a class to a class of paths longer by one. Aaaaaand this graph turns out to be a tree, where each vertex has a weight (number of paths in this class) and we have to pick a subset such that no pair ancestor-descendant is picked, so easy dp.

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

The solution to 1863E says: So if we define $$$f(x,y)$$$ to be the smallest $$$z\ge y$$$… Is it a typo that the latter $$$y$$$ should be $$$x$$$?

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

For the F solution, why do we want that s ^ mask_start > 0 or s ^ mask_end > 0?

(Also if my understanding is correct, are mask_start and mask_end suffix and prefix xors of the initial array? Or am I potentially misunderstanding this part?)

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

Can someone help me to solve problem E. I want to do it with topological sort, and in order to solve it, I need to solve one subproblem first. How can I get the smallest lexicographic configuration of topological sort. For example, if there are two correct toposort configurations [4,1,2,3] and [1,4,2,3], how can I get the second one? Thanks in advance

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

Is this round unrated now?

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

Why there is so many like? There aren't code in it,I think it bad.

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

Thanks for the editorial !! It helped me to upsolve.

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

why does this test case gives different answers for jiangly's and tourist's code for problem E

1 
11 10 15
2 12 9 8 11 14 12 8 10 5 11
5 2
5 3
2 4
3 4
1 3
1 6
1 7
6 8
9 10
9 11
»
6 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I think there is a typo in the editorial for E.

Where it says

"If we denote $$$w_v$$$ then it can be expressed as

$$$\max{\{ w_u : u - \gt v, c_u + k \gt c_v \}}$$$

"

It should be $$$\min$$$ rather than $$$\max$$$ since the goal is to find the first index that causes $$$c_v$$$ to increase by $$$k$$$.