3

Editorial for Hello 2023

 1 year ago
source link: https://codeforces.com/blog/entry/110629
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
By n0sk1ll, 9 days ago, In English

1779A - Hall of Fame

Author: n0sk1ll

Hint
Solution
Bonus Problem

1779B - MKnez's ConstructiveForces Task

Author: n0sk1ll

Hint 1
Hint 2
Solution
Bonus Problem

1779C - Least Prefix Sum

Author: n0sk1ll

Hint 1
Hint 2
Solution
Bonus Problem

1779D - Boris and His Amazing Haircut

Author: n0sk1ll

Stupid Hint
Hint
Solution
Bonus Problem

1779E - Anya's Simultaneous Exhibition

Author: n0sk1ll

Hint
Lemma 1
Lemma 2
Solution
Bonus Problem

1779F - Xorcerer's Stones

Author: n0sk1ll

Hint 1.1
Hint 1.2
Hint 1.3
Hint 2.1
Hint 2.2
Solution
Bonus Problem
Bonus Problem Hint

1779G - The Game of the Century

Author: Giove

Hint
Solution
Bonus Problem

1779H - Olympic Team Building

Author: n0sk1ll

Huge thanks to dario2994 for helping me solve and prepare this problem.

Hint 1
Hint 2
Fake Solution
Lemma
Solution
Bonus Problem
paperclip-16x16.png Tutorial of Hello 2023

37 hours ago, # |

very fast tutorial ;)

  • 37 hours ago, # ^ |

    very fast comment

    • 37 hours ago, # ^ |

      very fast reply

      • 37 hours ago, # ^ |

        Rev. 2  

        +8

        all of you very fast

        • 37 hours ago, # ^ |

          very fast seen

        • 37 hours ago, # ^ |

          not me :(

          • 37 hours ago, # ^ |

            very very fast

            • 36 hours ago, # ^ |

              late reply to something very fast

              • 36 hours ago, # ^ |

                very fast late reply

                • 36 hours ago, # ^ |

                  very fast seen the very fast late reply

                • 36 hours ago, # ^ |

                  Very last reply! Now stop!!

                • 35 hours ago, # ^ |

                  very fast swipe....!!

                • 33 hours ago, # ^ |

                  very fast stuff

                • 18 hours ago, # ^ |

                  fast reply on same level

  • 34 hours ago, # ^ |

    thank you for tutorial :)

37 hours ago, # |

Rev. 3  

0

amazing it's too fast!!!

37 hours ago, # |

Is this the fastest published editorial?

37 hours ago, # |

Too fast, Thank You!

37 hours ago, # |

These are, as of now, surely the best CF problems of 2023!

37 hours ago, # |

F is very similar to : THis Problem

37 hours ago, # |

this is awsomely fast ! thanks

37 hours ago, # |

Rev. 6  

-12

I want to know in Prob.A when I was submitting like for LR the answer is 1, why its wrong?

Since only 1 operation will be enough in this case if we find an "LR" occurence we can just swap it and it's done

  • 37 hours ago, # ^ |

    import java.io.BufferedOutputStream;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    
    public class HallOfFame {
       public static void main(String[] args) throws IOException {
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
    
          int t = Integer.parseInt(br.readLine());
          while (t-- > 0) {
             int n = Integer.parseInt(br.readLine());
             String str = br.readLine();
    
             int cR = 0;
             for (int i = 0; i < n; i++) {
                if (str.charAt(i) == 'R') {
                   cR++;
                }
             }
    
             if (cR == 0 || cR == n) {
                pw.println(-1);
                continue;
             }
    
             int res = 0;
    
             for (int i = 0; i < n - 1; i++) {
                if (str.charAt(i) == 'L' && str.charAt(i + 1) == 'R') {
                   res = i + 1;
                   break;
                }
             }
    
             pw.println(res);
    
          }
    
          br.close();
          pw.flush();
          pw.close();
       }
    }
    • 37 hours ago, # ^ |

      I know this too I just want to know that why it's not 1 but i+1. Only 1 can do the work or not?

      • 37 hours ago, # ^ |

      • 36 hours ago, # ^ |

        Consider the case: RRRLLR. If you intended to swap index 1 (or the 0th index), you fail to illuminate the trophy since index 1 and 2 are the same. Obviously, 'L' and 'R' are not fixed at index 1, so outputting 1 will be unreasonable.

        • 36 hours ago, # ^ |

          I am so stupid I didn't read it right I thought it said to input the operation .

          So stupiddddddddddd of me!!!!!!!!!!

  • 36 hours ago, # ^ |

    Output: For each test case print −1 if it is impossible to illuminate all trophies by performing one operation (or doing nothing). Otherwise, print 0 if you choose not to perform the operation (i.e., the trophies are illuminated by the initial positioning of the lamps), or an index i (1≤i<n) if you choose to swap lamps i and i+1.

37 hours ago, # |

Queue forces on C and D

37 hours ago, # |

Rev. 3  

0

my sol for C was basically to do some math. Starting at m you check all the contiguous sums down from m and up from m. For the sums on the left, they have to be less than or equal to 0 and for the sums on the right, they have to be greater than or equal to 0

Did anyone use a similar approach that worked? I got a WA on pretest 2.

Edit: So I looked at the editorial and while I'm still not clear on the solution, its helped. However, can someone poke holes at my logic here? I manipulated the inequality for cases where k was smaller than m and for cases where k was larger than m. When you do that, you get the following inequalities:

Case 1: (k < m) a_k+1 + a_k+2 + a_k+3 + . . . + a_m <= 0

Case 2: (k > m) a_m+1 + a_m+2 + a_m+3 + . . . + a_k >= 0

So for the first case, you get these inequalities that I've numbered on the left

(1) a_m <= 0

(2) a_m + a_m-1 <= 0

(3) a_m + a_m-1 + a_m-2 <= 0

. . .

(m-1) a_m + a_m-1 + a_m-2 + . . . + a_2 <= 0

For the second case, you get these inequalities that I've numbered on the left

(1) a_m+1 >= 0

(2) a_m+1 + a_m+2 >= 0

(3) a_m+1 + a_m+2 + a_m+3 >= 0

. . .

(n-m) a_m+1 + a_m+2 + a_m+3 + . . . + a_n >= 0

So I assumed that as long as you solved these cases independently and in order, you would get the optimal answer (go through inequalities numbered 1 through m-1 in case 1, and then go through the inequalities numbered 1 through n-m in case 2.

  • 37 hours ago, # ^ |

    For the sums on the left, you must iterate till i > 0, not i >= 0. Had made the same mistake at first. AC code: https://codeforces.com/contest/1779/submission/187800612

    • 37 hours ago, # ^ |

      I did do this in 187817105 though

      • 37 hours ago, # ^ |

        I did the same thing, we are not considering the maximum number from each subarray, I don't know why we should take that though in the pq

        • 37 hours ago, # ^ |

          How then would you find the max when you need it?

      • 37 hours ago, # ^ |

        As explained in the editorial you need to choose such element to perform operations on that causes our target prefix sum to decrease as much as possible. Current element i.e. will not always be that element.

        • 36 hours ago, # ^ |

          Could you help provide a test case that showcase why it is necessary? Thanks in advance!

      • 36 hours ago, # ^ |

        Take a look at Ticket 16655 from CF Stress for a counter example.

    • 36 hours ago, # ^ |

      did this because I assumed n == 1 is a special case :/

    • 35 hours ago, # ^ |

      But Why?

    • 21 hour(s) ago, # ^ |

      can you explain your solution ..

    • 16 hours ago, # ^ |

      Thank you for your code.I got it now. :)

  • 37 hours ago, # ^ |

    I`m too

  • 33 hours ago, # ^ |

    I'm stucking in the second case since I cannot get min flips I need, I'm using the same approach, just try this in the second case ... a[m] 12 -11 -2 -3 you can flip just -11 and you won't need to flip -2 and -3 so the min answer is 1 not 2

  • 24 hours ago, # ^ |

    I also used the same approach. After reading the tutorial what I am getting is that our approach was right but it does not always lead to the optimal answer. The constraints from the math can be satisfied with lesser operations using priority queue. Like the priority queue only picks a subset of numbers from the set of numbers modified in our approach and still satisfies the constraints.

  • 20 hours ago, # ^ |

    If you are still not clear, consider the inequalities a_m+1 + a_m+2>=0, let say they are 4 and -4 respectively, so techincally you dont need to change anything and now lets the next inequality , let a_m+3 be -2 so, now the sum is <0 , so you must change some elements, which will you prefer to change -2 or -4, obviously -4 since it contributes more to the positive sum, thats why you need to keep a priority queue or set for this purpose

    • 10 hours ago, # ^ |

      Thanks so much! That test case is pretty eye-opening.

37 hours ago, # |

Why is this solution to C wrong? 187783695

  • 36 hours ago, # ^ |

    Rev. 2  

    +1

    you are storing all the elements at first and then trying to compute the number of operations this doesn't take into consideration that a element at index X s.t. X<M would have the choices of only the elements in range (X,M] for negating in order to make any relative change to the values. .

    please see this for reference: https://youtu.be/kzCF4qpsjWQ let me know if you need further help :)

  • 36 hours ago, # ^ |

    Take a look at Ticket 16656 from CF Stress for a counter example.

37 hours ago, # |

It looks like someone was eagerly waiting for the clock to tick.

37 hours ago, # |

Could someone help? Why I got runtime 187832356

37 hours ago, # |

Explanations are very easy and clear.

37 hours ago, # |

wow, so fast!

37 hours ago, # |

super fast

37 hours ago, # |

E is brilliant!

37 hours ago, # |

submitted editorial in 0ms

37 hours ago, # |

Damn, B was very sneaky! Great problems!

  • 36 hours ago, # ^ |

    I messed up the maths once and kept wondering why is the solution wrong :P

37 hours ago, # |

Bonus for E (hopefully it's correct :)) Let's find outdegree for all people, call it deg[i]. It's sufficient to find minmum R such that there exists subset of people of size R such that their sum of outdegrees equals nCr(R, 2) + R * (N — R). I was thinking about this during contest but how do you implement it if you want to recover answer as well?? I mean can you do this faster than O(N^4), and in particular in better space complexity?

Btw amazing problemset.

    • 37 hours ago, # ^ |

      Wow, I'm so stupid. Obviously this is not equivalent to knapsack, since the answer always consists of some prefix of biggest outdegree guys...

37 hours ago, # |

My first contest in my life and the first contest in 2023

37 hours ago, # |

For problem F, the editorial says "Time complexity is and memory complexity is . It is possible to optimize this, but not necessary". I believe my code has the same complexity as said above but it got TLE at test 10 :( 187833020

  • 36 hours ago, # ^ |

    Never mind, I figured it out. Because of vector assignment(s).

37 hours ago, # |

The way you meet the New Year is the way you live the whole year: that fast editorial for all 2023 contests :)

37 hours ago, # |

The n = 3 case in B was really terrifying.

  • 36 hours ago, # ^ |

    You could have derived it. check here — https://youtu.be/2L326KCBqug ,but yes it gave a feeling that for odds answer would be NO :P!

37 hours ago, # |

Why did we look for i > j in problem E (lemma 2)? It seemed to me that i < j should. If I'm wrong, please explain why.

Sorry for my poor English

  • 37 hours ago, # ^ |

    You are right! should have been written. Thank you for pointing it out, I fixed it now.

37 hours ago, # |

FST is not a funny joke.

About E:

Interactive problems takes a lot time to test the sample of it , so I submit it with out testing the sample .

My program WA on pretest 2 , but pretest 2 is a sample and I don't think this should be deducted from the score .

If there many samples , and I get WA on 2 , in codefoeces's rules , should my score be deducted ? Is this a mistake ?

I don't know , TAT.

(My English is so bad.)

  • 37 hours ago, # ^ |

    And I think E is a good problem . But many people solve it with mindless guessing.

    • 37 hours ago, # ^ |

      What sort of mindless guessing?

  • 36 hours ago, # ^ |

    Only the first pretest is penalty-free, as per the rules.

37 hours ago, # |

I think that the author should swap E and F, it's so confusing.

37 hours ago, # |

Bonus problems. Yeah !!!

  • 22 hours ago, # ^ |

    Potatohead orz

37 hours ago, # |

I even cannot come up with the lemma 1 of problem E during the contest. Perhaps I've forgotten the knowledge of the Graph Theory I've learned.

37 hours ago, # |

Rev. 3  

+34

Bonus E :

View the match where player beat player as a directed edge from node to in a complete graph of vertices. Candidate masters are nodes that can be visited from all other nodes through some simple path (in other words, there exist a series of matches(=edges) to disqualify all other players).

All possible candidate masters are the nodes located in the last/terminal Strongly Connected Component(SCC) (SCC that doesnt have any outgoing edge to another SCC). As the graph is complete, this terminal SCC is unique.

For each node, find its outdegree. For the first nodes, do a simuls againts all other node(player) and count each of their loss match, with a total of queries. For the final node, calculate its outdegree from the remaining out/in-going edges from the previous nodes.

The terminal SCC (the candidate masters) are composed of the nodes with smallest outdegree such that their sum is equal to the number of edges among those nodes . Pick minimum such .

36 hours ago, # |

Very fast tutorial and Bonus Problems are really interesting

36 hours ago, # |

I don't know why this solution gets AC while it shouldn't (Problem D)

187838626

i used sparse table for RMQ but i forgot to initialize the logs array but it passed with no problem!

36 hours ago, # |

very fast tutorial

36 hours ago, # |

What will be generalized approach for Problem B bonus part ?

36 hours ago, # |

Rev. 2  

0

Bonus task for B:

Let n = km + r where 0 <= r <= m-1. Similar with original problem we get (k-1)s_m+s_r=0, where s_m = a1 + a2 + ... + am. When k = 1, r = 1, there's no solution because in this case a1 = s_1 = 0. Otherwise there exist some { a1, a2, ..., am } satisfy the condition. We let ai = a_(i-1)%m+1 for 1 <= i <= n and get a solution.

36 hours ago, # |

For rank1 to rank4, all of them got "wrong answer on pretest 2" at B for one time.

What a great problem!

35 hours ago, # |

I used vector in the iteration of F, and get stack overflow(maybe in fact MLE?) in the system test. Can anyone explain the reason? Thank you.

35 hours ago, # |

As a candidate master, I even CANNOT solve the problem E which is about finding "candidate master".

35 hours ago, # |

Why in problem C we are going till i>=1 and not i>=0?

  • 35 hours ago, # ^ |

    Rev. 2  

    0

    Baltic's favorite number is m, and he wants a1+a2+⋯+am to be the smallest of all non-empty prefix sums.

    "non-empty" means there's no need for p0 >= pm

    • 35 hours ago, # ^ |

      Thanks ! Got it.

    • 10 hours ago, # ^ |

      I still didn't get it. Can you explain it again

35 hours ago, # |

Even though I liked problem E myself, it felt weird that it was interactive, and not just giving degrees for each vertice, and asking the same. Can someone explain to me the reason it was given in such a way?

  • 30 hours ago, # ^ |

    Because red herrings make for cruel funny problems I suppose.

  • 14 hours ago, # ^ |

    Take a look at Ticket 16663 from CF Stress for a counter example.

35 hours ago, # |

anyone can explain this??

problem B solution
  • 35 hours ago, # ^ |

    they have performed mathematical operations and resolved it ... you might find this helpful : https://www.youtube.com/watch?v=2L326KCBqug&t=4s

    happy coding :)

  • 34 hours ago, # ^ |

    In problem b you can have two cases when n is even and when even is odd, this is how we derive the solution for both cases.

    case 1: n is even:->

    let the total sum of the array be s then a1+a2+....+an=s, and we also know that a1+a2=s and a3+a4=s and so on, therefore we get the equation, s*(n/2)=s.

    Now since n can not be 0 we conclude that s has to be 0,so the array looks something like

    [x -x x -x....x -x].

    case 2: n is odd:->

    let the total sum of the array be s then a1+a2+....+an=s, now we already know what we have to do when n is even therefore it makes sense to divide the array as 1(odd part)+(n-1)(even part), now we can extend the idea of case 1 for a2 to an, so we know that a2+a3=s, a4+a5=s and so on.. therefore the equation becomes a1+(n/2)*s=s, and we also know that a1+a2=s.

    Solving these two linear equations we get a1=s*(1-(n/2)) and a2=(n/2)*s, for simplicity i took s as 1. so the array looks something like:

    [(1-n/2) (n/2) (1-n/2) (n/2).....(1-n/2) (n/2)]

    here is my implementation of the problem: https://codeforces.com/contest/1779/submission/187770011

    • 25 hours ago, # ^ |

      so....what if n/2 bigger than 5000?

      • 24 hours ago, # ^ |

        see the range of n mate, it is upto 1000, and also i took s as 1 for that purpose.

35 hours ago, # |

Rev. 2  

+7

Alternative explanation for Div2D.

Observation 1: If for any , then the answer is NO.

So we may assume WLOG that for all .

Observation 2: We can restrict to using scissors in descending order of (i.e use taller scissors first, then go down in size). This is because if there is a solution using another order (not descending), then the same solution intervals but sorted in descending order of the scissors length is still a feasible solution.

Observation 3: We need a scissors of length to cut index .

Notation: For index i, let denote the next index after such that (i.e next bigger element in ). This can be preprocessed using a monotonic stack. This is a standard problem so I'll skip the details, but I'll assume you can precompute for all in time. See https://leetcode.com/problems/next-greater-element-ii/ for example.

I'll also treat as a set using to denote a value in the array .

For each , let be a set of all the indices with value : . We can divide into "slots" where each slot is separated by an element with value greater than . For example, first slot separated from second by , and so on.

This means that the interval for scissor with length cannot cross the slots in .

Now we proceed greedily. If , then there is no point using , so skip it.

If , then we look at . Take the smallest index , and let . We trim all the indices in in the range by repeatedly removing the smallest index until the slot is entirely trimmed. Some care should be taken if since we can skip this index (without starting a new slot).

And that's it, in the end, we check if after all the trimming. If it is, we return true, otherwise False.

C++ Implementation Details: is implemented as a map from int (value of ) to set where contains all the indices with value in .

Code: https://codeforces.com/contest/1779/submission/187842280

35 hours ago, # |

Can someone please explain lemma 2 of problem E in more simple words. I don’t get why degree of every vertex in Si will be higher than Sj for (i<j).Also why S1 is set of candidate masters.

35 hours ago, # |

Rev. 2  

-15

i may sound a fool or someone who have less knowledge but in problem H cant we just do :

  1. sort the array ( not the original but make another array that have same elements )

  2. Then we have the sorted array , so 1...n/2 elements we will put in an array namely smallelements(lets say), and next n/2+1...n elements in an array namely largeelements(lets say)

  3. Then with repsect to original array we will check that whether a[i] is present in which array (smallelments or largeelements)... if a[i] is in smallelements we will print '0' else if a[i] is in largeelements we will print 1.

  4. FOR THE CASES WHERE DISTINCT ELEMENTS ARE JUST '1' we will simply print 1 for n times

  • anyone can correct me please? why my this approach is wrong?
  • 35 hours ago, # ^ |

    Why would you think that it's correct?

    • 35 hours ago, # ^ |

      i am not saying this is correct, but i am asking to correct my thinking

      • 34 hours ago, # ^ |

        An easy way to see why it's incorrect is 1 2 3 10.

        There is simply nothing correct in your solution(except that the answer is all 1s if the elements are all equal). I'm really confused by how you came up with that solution.

        • 34 hours ago, # ^ |

          thanks for letting me know why it is incorrect, with time the approach will get good.

  • 27 hours ago, # ^ |

    Rev. 5  

    -24

    Because the problem H is designed for LGMs, so if someone is not, their approach will be very likely wrong.

    Update: wtf downvote???

    Update2: It's awful to get downvoted but don't know why...

35 hours ago, # |

Rev. 4  

0

D- Wrong Answer in 2. 187839619 [](https://codeforces.com/contest/1779/submission/187839619)

idea :

a-> 8 8 8 8 7 8 8

b-> 7 5 6 5 7 5 6

x-> 7 5 5 5 6 6

Output : YES

I'm storing all the elements of array b into a set in decreasing order.. First element is 7, so I'll take all the position of 7 of B and store them in an ordered set.. then for 6 I'll check if there is any value greater then 6, located in between two consecutive positions of 6.. If yes, then segment for 6 will increase... here two segments are needed for 6.. so the minimum occurrence of 6 in array x should be 2.. otherwise, ans is NO.. I'll check this for every unique value of array b..

Is there anything wrong with this idea?

  • 14 hours ago, # ^ |

    Take a look at Ticket 16662 from CF Stress for a counter example.

    • 11 hours ago, # ^ |

      Rev. 2  

      0

      Thanks.. Didn't know about this.

35 hours ago, # |

Fast & perfect editorial

34 hours ago, # |

This contest was probably not good for #1 tourist

31 hour(s) ago, # |

That moment when you realize all that time you were trying to solve a version of where in each game only player is chosen and the other is the winner of the previous game.

30 hours ago, # |

More and more vegetable,what should I do?

29 hours ago, # |

Thank for your fast tutorial!

28 hours ago, # |

We don't often see so fast tutorial like this.

28 hours ago, # |

I had great difficulty in C.

My idea was to use Segment tree but I WA on 2 many times. (Who can help to hack me? Please)

The Segment Tree includes the maxinum and the mininum of each section.

First, Reverse traversal [1~m-1].

if sum[i] < sum[m] — s1:

s1 = s1 + 2 * query_max{a_i+1~m}

update(the location of the maxinum, -maxinum)

Then, traversal [m+1~n].

if sum[i] + s2 < sum[m]:

s2 = s2 — 2 * query_min{a_m+1~n}

update(the location of the mininum, -mininum)

Please help.... QWQ

28 hours ago, # |

will there be a tutorial for bonus problem :")

26 hours ago, # |

jiangly fanbase strong

lol

25 hours ago, # |

Rev. 2  

0

can anyone please tell me where my solution is wrong:

https://codeforces.com/contest/1779/submission/187871735

Thanks in advance

Edit: nvmi.. i was stupid

25 hours ago, # |

Rev. 3  

+16

Bonus F: After using the hint 6, you will find that this problem equals to choosing some non intersecting subtrees and make them have an xor sum of . After you get a solution using whatever way (not neccessary with <=6 operations), you can make it within 6 steps using this simple trick about xor vector basis, and you will find that if it is possible to do so, you will always get an answer with less than steps.

  • 25 hours ago, # ^ |

    Rev. 2  

    +11

    Really appreciate that there is a 'bonus' for every problem, and can keep me think deeper about those interesting problems:)

24 hours ago, # |

n0sk1ll, any insights on how you implemented the adaptive checker for E?

  • 20 hours ago, # ^ |

    Usually, adaptive jury is implemented by fixing some invariant in the input. In this one, I fixed the whole tournament graph, but allowed permutations (i.e. the resulting graph after all participants' queries have been asked will be isomorphic to the jury's initially intended one). Jury permutes the graph in a way such that the newly asked vertices will always have the smallest possible (available) out-degree, meaning that there is practically no information about the winners before queries are asked.

    In fact, there exists a solution which uses exactly queries — the tests seem to be strong. (and in practice, all fake solutions fail to squeeze into queries, which was the constraint in the problem)

    • 20 hours ago, # ^ |

      Yeah, I always wondered how adaptive interactors are written. It seems an impressive idea to always have smallest possible out-degree during interaction.

      Thanks a lot for sharing!

23 hours ago, # |

I passed problem H with the following fix of the fake greedy:

While expanding from size 2 to size 4, we enumerate all the 15 ways instead of using greedy.

I don't know if it's correct or not. Can anyone prove its correctness or come up with a counterexample?

  • 8 hours ago, # ^ |

    My intuition suggests that this is wrong, but I also see why it may be hard to construct a counter test.

    n0sk1ll: Do you know how to construct a hack?

    • 8 hours ago, # ^ |

      Rev. 2  

      0

      My intuition tells me that one should still check at least subsets (in a greedy solution), and that there exist counter-tests. Although, I don't have a particular hack.

23 hours ago, # |

Rev. 2  

0

In Problem E Lemma 2,

We can also conclude that x has a higher out-degree than y for each x∈Si, y∈Sj, i<j.

How are we able to conclude this?

  • 21 hour(s) ago, # ^ |

    Please someone explain this

  • 21 hour(s) ago, # ^ |

    Because for every pair (i,j) (i<j) all players in Si beat all players in Sj. If that was not the case, then Si and Sj would be the same SCC.

21 hour(s) ago, # |

Anyone have solution Bonus Problem for C ?

21 hour(s) ago, # |

can someone please explain that does the editorial for Task — C means in simple terms and its implementation.

21 hour(s) ago, # |

1779D in second hint, I think it will be x >= bi

  • 21 hour(s) ago, # ^ |

    is correct, I fixed it now :)

20 hours ago, # |

Rev. 2  

0

How did some people used DSU in solving D ? Example jiangly

18 hours ago, # |

Can anybody explain me D problem solution using segment trees???

  • 16 hours ago, # ^ |

    I solved it using segment tree 187802839. The only purpose of the segment tree is to be able to calculate the maximum element of b in the range [l, r).

    I'll try to explain my solution.

    1. If for any i, b[i] > a[i], answer is NO.
    2. If a[i] == b[i] then this hair doesn't need a razor.
    3. If a[i] > b[i], then we need to cut hair i, and so there must be a razor with length b[i], else answer is NO.

    Now the only thing is that when we make a cut using razor x on the interval [l, r), there must not be any element of b in the range [l, r) such that b[i] > x. If there exist such b[i] > x, we will cut short i to length x < b[i] which can not be grown back.

    A conclusion from above is that maximum element of b in range [l, r) must be <= x. To find the maximum element of b in range [l, r) in O(log n) time, we use a segment tree. A even better data structure to use is a sparse table which can return the maximum of a range in O(1).

    All I do is store in a map, razor of which length will have to cut which indices. And then I try to distribute the ranges among all razors available of that length.

17 hours ago, # |

About problem H, I have two questions:

  1. How to construct a test with over subsets we have to consider (not , just ).
  2. How to implemented quickly in the meet in the middle part (I only know to use sort and binary search).
  • 17 hours ago, # ^ |

    1. Make all (reachable) big subsets intersect. I used different strategies, the simplest of which is generating numbers close to each other by value. There will be different subsets, all having similar value, and all are intersecting. Fill the rest of the array in a way such that the "smallest" subset can be extended into a full solution, but others cannot. In practice, more than subsets would have to be considered in any solution.

    2. Write two pointers instead of binary search. As for sorting, It is possible to sort all subsets of an array of length in . Consider that all subsets of some prefix are already sorted, let their array be where , and let be the new element we consider. The new subsets we add will have sums , and in that order since is sorted from previous steps. We only need to merge two already sorted arrays, which is possible in .

16 hours ago, # |

Can anyone explain how non-intersecting subtrees can be ensured in problem F?

15 hours ago, # |

I love these bounce problems thank you for the good contest (⁠。⁠♡⁠‿⁠♡⁠。⁠)

15 hours ago, # |

Rev. 2  

0

12 hours ago, # |

Rev. 3  

0

From the editorial of problem C:

why do we have to take the greatest x from them?

  • 9 hours ago, # ^ |

    Rev. 2  

    0

    Let m=5,

    1. We need p5<p4 => p4+a5<p4 => a5<0 (regardless of a1,a2,a3,a4)
    2. We need p5<p3 => p3+a4+a5<p3 => a4+a5<0 => a4<-a5 (regardless of a1,a2,a3)
    3. We need p5<p2 => p2+a3+a4+a5<p2 => a3+a4+a5<0 => a3<-a4-a5 (regardless of a1,a2)
    4. .................

11 hours ago, # |

I solved problem D all by myself (after the contest of course) using a monotonic stack approach. I have no one to share it with but I feel happy because that's probably the most challenging problem I've solved with no hints

6 hours ago, # |

In problem C, I'm wondering why moving from right to left is correct than moving from left to right

  • 3 minutes ago, # ^ |

    Let m=5,

    1. We need p5<p4 => p4+a5<p4 => a5<0 (regardless of a1,a2,a3,a4)
    2. We need p5<p3 => p3+a4+a5<p3 => a4+a5<0 => a4<-a5 (regardless of a1,a2,a3)
    3. We need p5<p2 => p2+a3+a4+a5<p2 => a3+a4+a5<0 => a3<-a4-a5 (regardless of a1,a2)
    4. .................

2 hours ago, # |

For D can someone point out a flaw in the following algorithm: 1)initially ensure a[i]>=b[i] for all 1<=i<=n 2)maintain a set of indices that have been "fixed" i.e you cannot cross them with another razor 3)now consider the largest element in b such that the index it is at is not fixed 4)now check whether or not we have a razor that has the required size, if there is no such razor we are forced to have a[i]==b[i] there and if that is not the case find the smallest element greater than current index in the set of fixed indices and we can use the razor in this segement(i.e starting from the current id to the lower bound of this id in the set) 5)also in my implementation I use a priorityqueue(multiset) to store b's i.e queue is ordered by greatest b and then smaller i implemntation:https://codeforces.com/contest/1779/submission/187982510 PS: ignore tc values(was trying to debug)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK