Educational Codeforces Round 95 Editorial
source link: https://codeforces.com/blog/entry/82673?f0a28=1
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.
20 months ago, # | Thanks for the editorial, the randomized solution to G is quite interesting. |
20 months ago, # | I think there also should be tag |
-
could you please explain your solution a bit?
-
Spoiler
-
I think you can model most dynamic programming problems like a graph problem. After all, dynamic programming states are nodes and transitions are directed edges. Together they create a DAG and in this problem you minimize the cost of the transitions.
-
-
Or maybe dijkstra is a DP algorithm?
-
Not sure why you're getting downvoted. When running Dijkstra's on a graph, we can consider the graph as being implicitly ordered according to the eventual costs of the nodes, with edges going from low cost to high cost. This graph is acyclic, and the cost of a single node is computed in terms of the nodes which have an edge directed into it, which is literally just DP. The only thing that makes it different from a "normal" DP algorithm is that we compute the topological ordering of the nodes on the fly, rather than knowing it beforehand.
-
The comment is hidden because of too negative feedback, click here to view it |
20 months ago, # | Can someone explain the segment tree solution of G . what i didn't understand is that valid regions depend upon the choice of right border and also on the number under consideration for eg. for the array 1 2 3 3 2 5 4 4 2 3 4 3 if we fix the right border at last index and took the number 4 under consideration then the valid/invalid regions will look like 0 0 0 0 0 0 0 1 1 1 1 0 . But these regions will change if we change the right border or the number under consideration . so there are total n*n such arrays . How can we keep track of them all with segment tree . Do we require multiple segment tree or one will suffice . |
-
One segment tree is enough. Consider which numbers change their segments when you proceed from some right border rr to r+1r+1. Easy to see that it's only ar+1ar+1. So we can actually clear the segments it contributed to and add the ones it contributes to now.
-
Thanks for explaining , just one query remaining. How do we update the regions when moving from r to r + 1, I mean a subarray can be bad not just because it doesn't has exactly 3 numbers of ar+1ar+1 but may be it doesn't have exactly three numbers of some other number . We can convert a good subarray to bad when moving from r to r + 1 , but how do we convert from bad to good. How do we know what numbers are making this a bad subarray .
-
You don't exactly store if the position is bad or good in the segtree. Each position only knows the number of bad segments it's covered by. For each bad segment [l;r][l;r] you add 1 on positions [l;r][l;r] in a segtree to maintain these values correct. And a position is good if the number of bad segments covering it is zero. Thus, adding a bad segment is adding 1 on a segment and removing a bad segment is subtracting 1 from a segment.
-
-
Such a clever and interesting approach for the problem E. I am interested to know if someone is able to solve it by going the usual way of (sum of damages for each perm / n! ) |
20 months ago, # | G and F should be swapped |
Can someone give me links for more problems similar to G in which I can use string hashing but not of strings directly? |
20 months ago, # | Hey awoo can you tell me more about the thinking process of G. Like how did you arrive at the conclusion that we can use numbers in base 3? |
-
Well, this xor hashing thingy is quite a common topic. I knew it because I encountered it multiple times. Initially the problem was to count the segments with 0 or 2 occurrences, so the usual xor worked perfectly.
Thus, for me the transition was only from bitwise to tritwise. BledDest suggested that idea and I found it pretty cool, props to him. Couldn't really come up with it myself.
-
Sir, I want to know one thing. Experience is a very important thing in competitive programming. But How to develop the power of innovating solutions to such problems? Like someone solved problem C with Djikstra....Everything cannot be covered by experience ..how are you able to think of new solutions to new problems???
-
20 months ago, # | |
-
The aniervs's solution was harder to interpret ( and I am still not able to understand it fully), but it would be great if an alternate solution of problem D is added to the editorial based on his idea just like you guys did for problem G(hashing and segment tree). It will help people like me in knowing different ways to tackle the problem. Also thanks for both unofficial editorial and this editorial... Learnt a lot!!
-
We (adedalic, if I am not mistaken) once set a similar problem about bringing some boxes to the same point, and we thought it was possible to solve it with ternary search. But, unfortunately, the function f(x)=minimum number of actions required to bring all items to position xf(x)=minimum number of actions required to bring all items to position x is not strictly convex because if there are two items in positions xx and x+1x+1, then f(x)=f(x+1)f(x)=f(x+1), but it is not necessarily the local minimum. Though there might be some way to handle it.
20 months ago, # | Hi awoo and adedalic . The way we have pushed the divisors into the set for all the values from ceil(l/x1) + 1 to floor(r/x1) in the way mentioned in the editorial solution is not clear ? Like as i understand that why we can't directly pushed all the divisors of all the numbers in the range with simple for loop of divisors of all the valid numbers of the segments . And also in the method of the solution we are also not clearing the set for further iterations of x1 is very complex to comprehend . Thanks for reading the comment and I will be grateful if you will explain . |
20 months ago, # | Can anyone help me identify what's wrong in my approach in C :
here's my submission : 92930622 |
-
There is a mistake in the line: if(i==0) ** {** ** return a[i]; // since my friend's turn is the first one** ** }**
so when you are calling ans(0,0) and ans(0,1) then you will get the same result as a[0] which shouldn't be. And really telling you only have to change only if(i==1) { if(j==0) return ans(i-1, 1); else return a[i] + ans(i-1,1); //as the first boss is only killed by the friend. }
And you can write more simpler version of it like these two : 1) https://codeforces.com/contest/1418/submission/92964444 2) https://codeforces.com/contest/1418/submission/92964444
20 months ago, # | Edit Request awoo I think in problem E tutorial, you mistakenly replaced all ajaj for bjbj in every max(K−aj,0)max(K−aj,0) expression. |
20 months ago, # | Thanks for the editorial . Greedy solution for C was really interesting. |
20 months ago, # | @vovuh Can you explain me what is wrong with my solution although I am partitioning the two halves with respect to the mid-point and it is giving right answer for all the given test case. But it gives wrong answer on submission. Can you help me where I am wrong Please? my solution link : https://codeforces.com/contest/1418/submission/92877522[user:vovuh]` |
20 months ago, # | @vovuh Can you explain me what is wrong with my solution although I am partitioning the two halves with respect to the mid-point and it is giving right answer for all the given test case. But it gives wrong answer on submission. Can you help me where I am wrong Please? my solution link : https://codeforces.com/contest/1418/submission/92877522 |
20 months ago, # | I've implemented the same code and it gives correct answer on my machine but it shows WA on Test Case 1. 92970290. I don't understand why this is happening. |
20 months ago, # | For G you would be better off using xor instead of sum. For each value generate two random integers x and y, and cyclically put x, y, x xor y in places with this value, the hash will be prefix xor. |
20 months ago, # | The comment is hidden because of too negative feedback, click here to view it |
-
It's more simpler if you use higher and lower methods instead of ceiling and floor.
20 months ago, # | i am getting runtime error in solution for problem c. can somebody help. https://codeforces.com/contest/1418/submission/92995605 |
20 months ago, # | In problem A, if I used the predefined ceil method(Java lang), it does not give the correct output. But If I did it in the other way, it is ok. Any idea? |
https://codeforces.com/contest/1418/submission/93095427 Why my greedy approach is wrong for the problem C? Please give me a case that fail the solution. Thank you. |
Thanks in Adavanced.., |
I had read the problem 1418B - Negative Prefixes for more than 40 min and after that I had read the solution but I wasn't able to understand these lines in block ,can any one help , I think it says we need to find array so that it prefix sum array should be like starting from negative elements and once the positive element came then there should be no negative elements(all elements after that are positive) like eg [−8,−14,−13,−9,−5,2,0] and as given in solution and k is 5 , and we need to reduce the k some and propose a solution ,but that was not the case
thanks in advance |
-
Ok so this is what it means. Lets have this prefix sum array [-1,-4,-5,-6,7,8,9]. Here, k = 4. This is because k is the index of the "right most negative element".
Another example: prefix sum array = [1,-3,4,-5,-1,2,3] Here, k = 5. The "right most negative element" is -1, and so its index is 5. You can have positive in between the negatives, it doesn't matter. What the problem is asking is you want k to be as small as possible.
So you want to arrange the array such that its prefix sum array will have the smallest k, when compared to other arrangements.
I hope this helps!
A solution for F without any data structures, just simple math (although with many steps and cases): For easier reading, let's rename (x1,y1,x2,y2)(x1,y1,x2,y2) to x,a,b,cx,a,b,c, so we need to find three numbers a,b,ca,b,c such that xa=bc∈[l,r];a,c∈[1,m];b∈[x+1,n]xa=bc∈[l,r];a,c∈[1,m];b∈[x+1,n]. In fact, we can drop the constraint on cc, it follows from the others. So far, we have fixed a value of xx. Now let's fix the greatest common divisor gg of b,xb,x. There can only be a total of nlognnlogn such divisors across all values of xx. The idea is to quickly find a solution given g,xg,x if it exists. We know that b>xb>x and since gg is their common divisor, we can write b=x+ygb=x+yg for some y>0y>0. The constraint on bb becomes y≤n−xgy≤n−xg. Also, since bb divides axax, we have that b/gb/g divides a(x/g)a(x/g) and so, since b/gb/g and x/gx/g are coprime, b/gb/g divides aa, and so a=(b/g)z=(x/g+y)za=(b/g)z=(x/g+y)z for some zz. Let's handle two cases: 1) g>x−−√g>x. In this case there can be at most x/g<x−−√x/g<x different values of yy and we can try each. For a fixed yy, we check whether bb fits the constraints and whether we can find zz such that aa also fits the constraints. 2) g≤x−−√g≤x. We try each value of zz as long as aa is less than mm. In fact, from a=(x/g+y)za=(x/g+y)z and y>0y>0 we have z≤mx/g+1z≤mx/g+1. After fixing zz, we look for yy to fulfil the linear constraints given above (a couple of integer divisions and min/max). Overall, the sum of small divisors (less than x−−√x for all numbers xx up to nn is asymptotically O(nn−−√)O(nn), and the sum of all values 1x/g+11x/g+1 for all small divisors is asymptotically equal to O(n−−√)O(n), so the overall complexity is (n+m)n−−√(n+m)n. |
19 months ago, # | https://codeforces.com/contest/1418/submission/94884520 Why is the greedy approach not working in this solution for the C problem? |
16 months ago, # | How to compute the probability of collision in problem G? Would some love to elaborate why it is the same as two vectors (out of n) colliding in a K-dimensional space with their coordinates being from 0 to 2? I will appreciate it a lot. |
13 months ago, # |
Can anyone tell what's wrong in the code? |
could anyone please tell me that how we are getting x-1 sticks in the first problem?I am thinking x sticks. |
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK