Codeforces Round 901 (Div. 1, Div. 2) Editorial
source link: https://codeforces.com/blog/entry/120943
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.
Codeforces Round 901 (Div. 1, Div. 2) Editorial
By Atomic-Jellyfish, 5 months ago,
I apologize for the unreasonable difficulty. I'm sorry :( |
-
chill, in my opinion the round was great, ABCD and F were great problems (although D might be a bit too easy for a D?). It seemed that div1 was too hard but I guess that such things happen and can't be predicted.
I'm looking forward to compete into one of your rounds again :)
5 months ago, # | At some point I have just started guessing C and it worked 226022161 (only if I didn't forget to take n modulo m first) |
5 months ago, # | Why my O(n^2) solution fails 226039678? Thanks in advance |
-
https://codeforces.com/contest/1875/submission/226075447
Change ur code a little bit(just removing maps cuz of shit const factor and adding vector as cnt). Always be careful with maps(never use it when it isn't necessary)
5 months ago, # | tilted asf, how to become better on coming up with ideas for DP, ABC superfast and ... no way, i wasted 2.5 h on D and didnt solve it, but came up with O(n^3) solution first, then O(n^2*logn), tl.. |
I have one doubt . in Div2C how do we know, that for the given set of powers it is always possible to divide the apples , in a away that all m people will get that set of powers? |
-
Each person needs apples. We can divide each of the apples into pieces, then each piece is , Each person takes pieces.
This is only possible since is a power of two, otherwise we would not be able to divide an apple into pieces.
-
thats almost right...consider n = 3 and m = 24 here m is not a power of two but its still possible....thats why actually m/gcd(m,n) should be a power of two ;)
-
Yes what I did was take gcd, divide it from m and n at the beginning, then multiply back at the end
-
-
In my opinion,if there are 7 apples for 4 persons,you should give 1 apple for each person,so there are 3 apples(3 pieces) now.And we know no one will get a whole apple(a whole piece),so we should devide every piece into two,now we have 6 pieces.After giving every person a piece,there are 2 pieces now.As what I just said,no one will get a whole piece,so we should devide every piece into two,now there are 4 pieces for 4 person,perfect!
I can't understand this statement:
I just made 2000 iterations simulating the process:
|
-
suppose after some large no (let it be a) of iterations, let x be (n*2^a) then -> x%m (according to your code only)
now, x%m to be zero m should be the divisor of x.
now m can be in the form of something * 2^(something else).
now this something cannot come from 2^a so it should come from n (see x=n*2^a) therefore m/(__gcd(n, m)) should not have any other prime factors other than two because 2 (in other words __gcd(n,m) should take all factors from m which are not 2) can be taken care by 2^a, but remaining factors have to be taken care by n itself.
explanation might be bad english not my native language.
-
Help me understand this in a better way, please.
-
If you can give everyone the same piece then (n * 2^k = 0) mod m, or n * 2^k = q * m. You can factor out gcd(n, m) to get
a * 2^k = q * b, where a = n / gcd(n, m) and b = m / gcd(n, m).
Now if b is a power of 2, then q = a and 2^k = b satisfies the equation. But if b is not a power of 2, then b has some additional factor(s) that is not found in a (because a is coprime to b) and 2^k (since b is not a power of 2).
-
5 months ago, # | A simpler implementation for problem B- (Not the most optimized but it works) https://codeforces.com/contest/1875/submission/225973389 |
-
More simpler and optimised approach -
If K is odd jellyfish can always take max of Gellyfish and give him his minimum, and then Gellyfish will try to get his maximum back in next move and then again jellyfish will take it back in another move and it continues this way until all K rounds.
If K is even, jellyfish can choose not to move if his min is greater then Gellyfish max. But still in this case Gellyfish will try to take jellyfish max as it will benefit him, and again like the odd case the game continues but this time Gellyfish would have the last move. 226072584
In problem , ternary search for finding the optimal works for some reason. In problem , does pass without any D&C, just by computing the convolution of and for every (used the fastest 1000 lines long implementation from yosupo judge). |
5 months ago, # | "Note that the sum of n over all test cases is not bounded." what does this mean in Div2 A problem? |
Div2D problem can be solved in time and memory. Let's say that mex values we add to the total score are interesting values. So main the observation is that there are that can be interesting values. Proof: Define as the count of in the array. Suppose that , and . We will not select both of them as interesting because it's enough to choose one. So if we choose its contribution to the answer is and if we choose the contribution is , and as it's optimal to choose . For every , it's enough to choose minimal as interesting value and as there are at most interesting values. We can do DP as in editorial but only with values that can be interesting. Total complexity is . |
-
i did not understand it clearly could you explain with this example??
0 0 0 0 0 1 1 1 1 2 2 2 3 3 4
-
For this example, . Also , , , and . So 0, 1, 2, 3, and 4 (5 numbers) can be interesting values. And . We do DP only for these numbers.
Let's see another example. 0 1 2 2 3 3 4 4 4 5 5 5 6 6 6 6 7 7 7 7. For this example only numbers 0, 2, 4, 6 (4 numbers) can be interesting. .
And for any array count of possible interesting numbers won't exceed .
-
-
Actually complexity is or . Because you need too count numbers.
5 months ago, # | how the equation m×|S|−n come out in the problem Div2C? Can anyone explain this? There is no any additional comments about this in Editorial. |
-
|S| is the number of pieces of apple each person is going to get , so m*|S| will be the total number of pieces they are going to get. Since each cut increase the number of pieces by 1 and initially there are n pieces when there are 0 cuts hence for x pieces we have to make x-n cuts and hence number of cuts will be m*|S| — n.
-
I was also stuck in how builtin_popcount_ ( or the number of set bits in a) is equal to the value of m. I got it like this:
If each person gets a/b (simplest form of n/m) weight of apple: It is represented as 1/2^k + 1/2^l + .... and sum of all these individual parts for a person is equal to a/b. a will be the numerator . Also, we notice that on adding these we will get just some powers of 2 in numerator . and lets say 2^p + 2^q +.... =a So number of pieces for each person can be obtained as number of different powers of 2 that add up to form the numerator . ie (a), and this is just equal to the number of set bits in 'a'. Also, in one cut we get 1 extra pieces , so for m*|S| pieces , we need to make m*|s| -n cuts, as we already had n pieces when 0 cuts were made (as explained by the person above)
5 months ago, # | For Div1C, can someone please explain why is different for each , I don't get it, it should be same according to me. |
-
It depends on what is ?
is probability that both of them chose , possibility after destroying some roads.
Let's say graph has 4 outgoing edges from 1, aka ,,,,
Let , , , .During the first turn, Asuka will choose all nodes with equal probability, so for maximum probability to reach n, Jellyfish should choose , there .
The second turn happens only if Asuka does not choose in the first turn.
If still exists for the second turn, Jellyfish should choose it. , (Asuka chose 3/4 in the first turn and 2 in the second turn).
If does not exist, then Jellyfish should choose , . (Asuka chose 2 in the first turn, and then 3 in the second turn)Jellyfish will not get a third turn; he will never choose , ,
-
Can you explain why f[i] = f[j]*p[j] ?
-
It's via linearity of expectation/probability.
If one is at , the next possible outcome is one move to one of the nodes () with an edge and eventually moves to , or one remains stuck there.
So, the probability of reaching from will be the probability of moving from to one of the adjacent nodes multiplied by their probability to reach , and (probability to reach after being struck on node ) multiplied by probability to remain stuck there.
Sure enough, you can also add other non-adjacent nodes in this equation but the probability of reaching them from is .
-
-
By calculating, p=[0.25,0.25,0.125,0] , it also satisfies the condition.
how can we be sure it satisfies the condition without checking all cases??
-
One cannot find all probabilities without checking all cases, just that you can memorise the subproblems via appropriate dp.
-
-
Thanks, I misunderstood the problem twice, but your explanation made it very clear why the 's would be different. But, the only issue is to calculate these 's in general, how did you extended this approach for any general outgoing edges?
-
Asuka chooses randomly with equal probability; by exchanging arguments, one can conclude that Jellyfish should always choose the one with the highest , still around.
Sort all the possible nodes in the adjacency list in descending order; then, we want to find of each of them, with the condition that Jellyfish will always choose the first available one.
We can define the following as the probability of selecting th person in a sequence of people.
DP transitions
-
-
How do you calculate p2? If Asuka chooses 3/4 in the first move, then this probability = 2/5 = 0.4, and from there, for Asuka to pick 2, it should be 1/3. So p2 should be (2/5)*(1/3) right?
-
5 months ago, # | You can easily optimise the Div2 D solution to O(N) by noticing that you will ever only consider deleting O(sqrt(N)) distinct elements. As the author mentioned, the deletions will be of strictly descending value but they will also be of strictly ascending count of appearance. Of course the sum of the counts of the elements we erase is bounded by N and since the counts will be distinct as mentioned earlier, the number of elements we consider erasing is O(sqrt(N)) (this is because in the worst case the counts are 1, 2, 3, .. and the sum of this series is quadratic). Then we can just do the same DP with complexity O(sqrt(N)^2) = O(N). |
5 months ago, # | For question C, turns out 1000 operations fits under the time limit and satisfies an "infinite" number of operations 226038405 :) |
5 months ago, # | Can anybody tell Why does my code for the problem C .Jellyfish and Green Apple works exactly at first I was getting TLE because of while loop so I just changed it to a condition that it won't go over 200 and my logic uses binary search on the pre-calculated 2^n array to calculat the next nearest number in which apples can be divided and then add upto answer and if at any point apples can be divided equally among m I get my answer if not in 200 moves answer is -1. Hope somebody gets what I am trying to say ;) |
5 months ago, # | Number of Submissions(E)*Submissions(F)*Submissions(G)<Submissions(D) |
5 months ago, # | One of the "I was also a problem setter on codeforces" round, that will go down in the resume. |
5 months ago, # | Please someone explain the mathematics behind the Div2C problem as mentioned in editorial in detail. |
5 months ago, # | Since it's cut in half every time, if m/gcd(n,m) is not an integral power of 2, there's no solution. (Div 2C) Can anyone explain this statement? |
For Div1 C, you can also think of the solution as writing n/m in binary such that the mantissa is not recurring. Why? Because you will divide the apples in powers of 2 and sum them to get n/m, which is possible in finite steps only if the sequence terminates. And how do we know that if the mantissa is recurring? Well, if you get remainder 0 at some step then it terminates. And if you get the same reminder again, then it doesn't. To avoid storing digits, you can just check if the number is longer than 32 bits, if not, then it is recurring since its modulo is bounded and it can't extend to a digit longer than that. |
5 months ago, # | Can someone clarify the middle paragraph in Div1.B? I don't understand why we need +1 in 4^8. Also are the nodes in the BFS functions? thx in advance |
5 months ago, # | I think tests for Div1C are not great because my solution runs in time sum of squares of degrees which is in the worst case, and I think it should be just about ok to pass the time limit. However, in reality my solution works in 75ms which is even faster than most of the other solutions that work in time . |
Can someone explain me why my solution is wrong for div2 question 1. 226083957 Thought process is that whenever the timer comes to 1 we add the array element, now we have 1+array element seconds left until bomb explodes ( obviously if 1+array element is greater than permissible value then I will just take the permissible value, formally min(arr[i]+1, a) ) now we just sum this up for each element and the answer will be initial timer value + sum b + sum should be answer isn't it? |
-
You have
int
overflow, uselong long
instead-
Thanks, that does solve the problem. But one thing which I now started to have question is that why was I subtracting n from my answer.
-
This was the best contest I have ever faced in a while. I enjoyed the problems so much. Thank you Atomic-Jellyfish. I solved Div. 1 D/Div. 2 G in using an observation I didn't try to prove. First of all, I arrived at the formula that the answer is and optimize the nested sum using DP. I noted that the sum is simply if . I used a slightly different dp transition with states (current index, sum of weights so far) to obtain the following formula which can therefore be altered to Now, the observation is as follows: Observation This is the observation stated formally. Now, what is this really trying to say is that we can treat each as a function in the form of with , and we plug in . Now, we need a data structure to store the maintain the minimum of these functions at a given . Assume for all . We can calculate for each from to , and since the minimization is done over , we may loop over from down to and we may insert the function in the data structure for minimization. So, we see that the data structure receives the functions in the form of where keeps strictly decreasing. Now, to maintain what is the minimum function at , we use the observation that we noted. We maintain a deque (or monotonic stack) containing pairs where and . When we receive a new , it must be that , and (1) and (2) in the observation tell us that if , then we don't care since will be minimal at every non-negative . If , we insert in the front of the deque, since (3) in the observation tells us that there is an intersection where will become less than and thus optimal. Finally, we note from (4) that the intersections of the functions in our data structure are increasing, and between each two intersections one function overtakes the other function as being the optimal. So, we can note that while the current is greater than the intersection of the last two functions in the deque, we can just remove the last function. Then, we query at in the last function in the deque. This works in Amortized . Note: I calculated the intersections using equations from Wolfram Alpha. Here is my submission. |
5 months ago, # | In Div2 D, why do we need to subtract the initial MEX from |
5 months ago, # | Can anybody explain me why my code in problem C was showing tle
but when i iterate in while loop for less than 60 iteration it passes |
5 months ago, # | Can anyone prove that precision error wont blow up in D1C? |
5 months ago, # | Great contest... |
5 months ago, # | thx for the round, really cool div1B, I love it. |
5 months ago, # | Amazing Div1B ! |
What's the feeling when you solved Div2.G with... |
-
What is quadrangle inequality?
5 months ago, # | Where is the solution of 1875B? |
5 months ago, # | Can someone explain me ,I have some doubt in 1875C — Jellyfish and Green Apple I got till this part So we can uniquely find a set of positive integers S satisfying nm=∑i∈S12i But how we get the answer by ,what is the logic We can use std::__builtin_popcount() to get |S|, the answer is m×|S|−n. And moreover since we devided n and m by gcd(n,m), so first ideally we should compute no of operation for one group(the group we get by deviding m by gcd(m,n)) and then multiply that with gcd(n,m) to get the total operation. |
-
Each cut increases the number of apples by 1. Since each person needs to get |S| apples in his account, final number of apples will be m*|S|. Since there were initially n apples, so we get the cuts by subtracting this from final apples, hence the answer m*|S| — n.
Also, for the intuition why to multiply a group ans by gcd(n,m) (as you say) goes by the following example. Suppose n = 30, m = 48. Then a = n/gcd(n,m) = 5 and b = m/gcd(n,m).= 8. Ans for one group is = 8*2-5 = 11. Now the number of groups have become 6 i.e. gcd(n,m). Hence the answer will be 11*6 = 66, which is same as that given by taking all n and m (48*2 — 30) = 66.
5 months ago, # | Fun fact: we add 1B to prevent the large gap between 1A and 1C. And Atomic-Jellyfish got the idea of 1G, when playing game. (xd |
-
The funny thing is that without 1B the gap would've been smaller :)
5 months ago, # | I regret misunderstanding problem B !! |
In div1 B, why there is cases instead of cases? |
-
Oh i understand
-
can you explain...i am still not getting it
-
Because your are going to record the shortest path's source and destinations, and since there maybe some types of that will not exist in the , so except for all that is , there is another destination called "not exist", so the state is in total .
-
what do you exactly mean by "some types of (ai,bi,mi) that will not exist in the (a,b,m)" ? can you give any example...thanks a lot
-
For example, , in this case, pair exist and others like not exist, so you only need to consider the shortest path from to there specific , so except the state , in the pre-calculation there is another state which is "not exist"
-
can you also attach your submission...tutorial solution is too complicated to understand
-
I think the author used some math (base 5 number representation and bitmask) to encode the states.
Let's see what does mean again? (thanks many helpful friend here helped me to understand it)
First, let's clarify this: Given same state of two different bit and , no matter what we do, the resulting bits at position in must be the same.
From then we can just care about different . For multiple bits that have same , we can use one to represent the whole group. Now, effectively all numbers can be seen as some special 8-bit numbers.
The base, if is in range , then corresponds to 4 cases of some arbitrary we can make from some . If base equals , it means that there isn't any such that forms the configuration we're considering
The exponent, from to , corresponds to the position, or more precisely the group I mentioned above.
Take a look at this example:
00004002
is a base-5 number corresponding to a state:Last digit is . It means that the 0-th group, which is , has
3-th digit is , it means that the group contains no bit in it!
For the remaining 6 groups, they just have the same
So why do we have to represent data this way? In this representation, we see:
Destination and Starting point are being tied together (with destinations as digits, and starting point as position (or call it order, exponent, ...))
Although we kind of "separated" individual bits to come up with the solution, yet in the solution they must be stored together !? Because each operation AND, OR, XOR affects each bit of the numbers. They're all transforming after each operation, so their values must be recorded and observed altogether.
-
-
-
-
5 months ago, # | For E,how can I use BFS(breadth-first search) for preprocessing? I wonder why to use BFS and how to use BFS. |
-
Each state of the numbers is a node, each operation changing from one state to another is an edge.
Therefore, a sequence of operations that transforms the init. configuration to the desired configuration, is a path between 2 nodes.
And minimum number of operations is just equivalent to the shortest path. In this case, it's unweighted graph so BFS is sufficient
5 months ago, # | Can someone explain me in div2 A, how answer is min(a-1,xi) ? cause at c=1, we use another tool so one second of xi is wasted so shouldn't be min(a-1,xi-1)? |
5 months ago, # | In problem 1B, why there are states instead of just ? |
Could somebody elaborate the following editorial for Div1D?
Does it mean that is there a way to directly evaluate for each in time? And what does it have to do with dot product? |
-
I think what is meant is that you store all in point value form , for points.
Convenient is to use the points . All operations needed (summing, convolving two polynomials, shifting the polynomial with ) can be done in time linear in the size of the representation, so in . Afterwards, the only thing left is from the point value form of , going back to the coefficient form. This can be done with the lagrange interpolation formula in with some tricks (You need to first with brute force calculate the coefficients of the polynomial , and do polynomial division to obtain each of the summands of the lagrange interpolation polynomial.
-
Ah, now I understand! So let me rephrase it:
- For each , we want to evaluate . (I wrote to emphasize that we want to find a scalar, not a polynomial)
- To do so, let us fix :
- Then it is sufficient to find the sequence of , successively from the initial element to the final.
- The recurrence relation enables us to find for each in an time.
- Thus, can be found in an time.
- Therefore, can be found in a total of time.
All that left is to do Lagrange interpolation, which I understand well. Thanks a lot for the explanation!
-
5 months ago, # | Why my solution fails 226099505? Thanks in advance! The input and output of my answer are the same as the example!!! |
5 months ago, # | can someone explain div2A. Why it isn't min(a-1, x-1) according to the condition |
5 months ago, # | any better explaination for div2 c? |
-
I'll try to explain it as best as I can.
When dividing the n apples among the m people, if n is greater than or equal to m, we can give each person n // m apples. After doing this, we can disregard how many apples each person has because they all have the same amount. We can now focus on the n % m remaining apples.
Let's say a = n % m. If we have no remaining apples (a == 0), then we have finished. Otherwise, we have to make a cuts to now give us 2 * a apples. If (2 * a) % m == 0, then we have finished. Otherwise, we have to make 2 * a more cuts to give us 4 * a apples. We do this until (a * 2^k) % m == 0, where k is the minimum number that satisfies the equation.
Now we have to figure out when there is no answer. In order for there to be an answer, (a * 2^k) % m == 0. This means that a * 2^k == q * m for some integer q. In order for this equation to be satisfied, all of m's non-2 factors must also be in a. If m had a non-2 factor that weren't in a, then it wouldn't be a divisor (it can have some factors of 2 that aren't in a because of the 2^k factor). This means that gcd(a, m) must have all of the non-2 factors that m has. This means that m / gcd(a, m) must be a power of 2. We can perform this check at the beginning of program and then proceed.
Here is what I did: https://codeforces.com/contest/1875/submission/226131697
-
If m had a non-2 factor that weren't in a, then it wouldn't be a divisor (it can have some factors of 2 that aren't in a because of the 2^k factor). This means that gcd(a, m) must have all of the non-2 factors that m has.
a * 2^k == q * m
why q was not consider, can it have non-2 factors?
-
Let's ignore the 2^k for now. If a = q * m, it means that both q and m are factors of a. Therefore a must have any factors that q and m has. If a didn't have a factor that m has, for example, we could have something like 3^2 = q * (3 * 5), and there is no positive integer solution here for q.
So, by this logic, we can see that all of m's factors must be present in a, so therefore gcd(a, m) = m, and m / gcd(a, m) = m / m = 1 (or in the original problem it must be 2^c for some c). So at the end of the day, q doesn't really matter at all.
-
5 months ago, # | i learned a lot from problem C, thank you Atomic-Jellyfish |
|
5 months ago, # | In Div2C, Why the answer in the tutorial is m×|S|−n. Anyone help me pls, I was thinking from yesterday. |
5 months ago, # | For 1875C - Jellyfish and Green Apple can you please explain: why __builtin_popcount(a) is equal to |S|? |
-
I hope you understood the part where
**m/gcd(n,m) is a power of 2 = 2^k**
Consider n/m = (a*gcd(n, m))/m = a/(m/(gcd(n, m))) = a/(2^k) where 2^k>a
Now divide "a" in the powers of 2. ( which are the set bits in the binary representation of a). Say the set bits are at position "i1, i2, i3, i4, and so on to ip" so
a = 2^(i1)+2^(i2)+ ... + 2^(ip)
n/m = (2^(i1)+2^(i2)+ ... + 2^(Ip))/(2^k) = 1/(2^(k-i1))+1/(2^(k-i2))+ ... + 1/(2^(k-ip))
All the k-i's belong to the set S. Hence, |S| = __builtin_popcount(a) = no. of set bits in a.
5 months ago, # | Think there's a mistake in 1874C — Jellyfish and EVA tutorial. The transition should be: |
-
Typo, thanks for the correction!
-
For 1875C — Jellyfish and Green Apple can you please explain: why __builtin_popcount(a) is equal to |S|?
-
For example, if a = 13, b = 32, each person will get 3 pieces of apple, a is 1101 in binary, 1101 = 1000 + 100 + 1(in binary), which is an apple piece with 8/32 kg, an apple piece with 4/32 kg, an apple piece with 1/32 kg.
-
ok i got this but why you have taken a = n / __gcd(n, m)??
-
We need to reduce it to its simplest fraction. for example, n = 5, m = 20, n/m = 5/20 = 1/4, the popcount of n is 2 but the popcount of a is 1.
-
-
-
-
5 months ago, # | Can someone please explain the editorial of D1B? |
5 months ago, # | can someone please explain why gcd(m,n) in problem C Div.2 |
5 months ago, # | Need a better explanation for div 2 E. It doesn't provide details about what preprocessing you're doing and how it helps in solving the tests. |
-
Hi! https://codeforces.com/blog/entry/120969 I have provided a bit more explanation here! Please upvote it you find it useful!
-
Thanks that was way more clear. Atomic-Jellyfish please consider linking it in the editorial.
-
5 months ago, # | Atomic-Jellyfish may you explain a bit in detail what you mean "by greedy and induction" we would arrive at those conclusions? what induction step is there ? greedy would be I think just wanted to make the sum more at each round by the one who is making the move . |
-
"By greedy and induction" means, we can get the result of k rounds of the game from the result of k-1 rounds of the game, for example, if k=2, Jellyfish will know what Gellyfish will do in the next round, which is the result of k=1, this is "induction". The result of k=1 is very easy, which is written in the tutorial — swap the max and min. Thus when k = 2, you can predict what your opponent will do next, for each of your operational scenarios, you will choose the best one, this is "greedy"
5 months ago, # | How do we prove that the optimal answer is m×|S|−n for Div2 C? . |
-
Somehow i managed to prove it myself.
Let us assume that is a power of . So we can say that can be finitely represented as some binary representation like .Each individual people is going to get weight of apples and he will get this weight in denominations of . For each in we need to have exactly pieces . For an apple of weight we can get pieces each weighting and this will cost cuts. For each in we need to have exactly pieces each weighting and it can be done using number of apples having initial weight of and for each apples it will cost cuts . For each in we would need exactly cuts . Total number of cuts will be . We know that , then .So, the expression .
5 months ago, # | It’s a pity that after problem B there are no problem tags.(and in general no problem *level ) |
Solution for Div2 D with comments:
|
5 months ago, # | Great Round! div.1 CD are both counting problems, typical style of CNOI ig |
5 months ago, # | Can someone explain to me why "Since it's cut in half every time, if m/gcd(n,m) is not an integral power of 2, there's no solution." must hold? |
5 months ago, # | In problem 1874C — Jellyfish and EVA, in second test case, I have no idea why the output is "0.625000000000".Please explain to me. |
5 months ago, # | i understand the implement of div2G but i still don't know how do we get that formula. Can anyone help me explain that formula |
5 months ago, # | amzing solution about div2c! |
5 months ago, # | I didn't understand how the graph is constructed in JellyFish and Math problem, author of this editorial didn't explicitly explain how it is done, and I am not able to figure it out from the code, any help will be appreciated. Thank you |
-
I've understood the problem, I'am going to write up the solution in complete detail because I believe the solution provided leaves out a lot of detail that are not obvious at all
First we need to encode reachability information from initial state of We do that by focusing on each bit of and as follows (since bits are independent and same bit combination goes together)
We're going to represent reachability information from initial state as follows
For each possible combination of initial state there are only 4 possible states it can reach to , and there are 8 possible initial states, so we can represent each of them using a 8-digit base 4 number, and we're only going to need possible configurations.
Example : for configuration
00001003
- initial state (0,0,0) can reach 3 = (1,1)
- initial state (0,1,1) can reach 1 = (0,1)
- all the other state can reach (0,0)
What is the initial configuration ? It is simple, for each digit corresponding to , its value is simply
Now, we want to find all such reachable configurations (cause clearly not all configurations are reachable), we do that by using the operations to define transitions
Each configuration can reach to exactly 4 different configurations in a single step (using the different operations given as follows)
Using operation op, we define the transition as
For each digit corresponding to state , say it is we create new reachable state given by operation op (eg: in case of we have , )
Remark : We're changing all the digits because from a configuration of , in one operation it changes all of its bits, so the all 8 groups must be changed to reflect that.
All the configurations reachable from initial config in this graph are exactly all those configs that are reachable from init config (preserving the number of steps), kind of obvious but this construction is quite meticulous
Now that we have this graph we can do a BFS over it starting from initial configuration, and we can get all the states reachable from it along with minimum number of steps to reach that particular state.
Now, given , we need to find a configuration where for each digit we have value at that digit, to find that we simply compute that configuration as say
config
and compute dist[config].In case we get in consistency, while computing config i.e. if different bits of input corresponding to same values but has different value, then that configuration is not reachable. Doing this requires 5 states instead of 4. (so we'll instead encode using 5 base numbers, using 4 to specify state isn't set or we can say 4 is don't care)
What if dist[config] == INF ? In this case we do not have any immediate inconsistencies, but the state is simply not reachable in the directed graph
Hope that was helpful
5 months ago, # | if m/gcd(n,m) is not an integral power of 2, there's no solution. can someone explain me this line of editorial of div2 question3 |
5 months ago, # | It's very interesting that 1C doesn't involve determining an actual optimal strategy, but instead we somehow just skip that and directly calculate the probability distribution of outcomes in an optimal strategy. Not sure I followed how we ensure that the derived distribution corresponds to a valid strategy though. And how do you even come up with the recursion for ? |
3 months ago, # | solution to A part Jellyfish and Undertale in python: for i in range(int(input())): a,b,n=map(int,input().split()) lst=list(map(int,input().split())) z=b for num in lst: z+=min(num,a-1) print(z) |
Can someone explain why my method for calculating the expected number of step to reach in Div.1 D is wrong? I think on this for a few times but still can't find what stuff goes wrong :/ My approach is as followed: First consider using linearity of expectation, we will get then obviously every edge will be traversed from left to right, and every time it got traversed from right to left, it will also be traversed from left to right eventually, so we have which lead to the final answer |
98 minutes ago, # | includeincludeincludeusing namespace std; void solve() { long long int a, b, n; cin >> a >> b >> n; vector<long long int> v; int x; for (int i = 0; i < n; ++i) { cin>>x; v.push_back(x); } int flag = 0; int k = 0; long long int sec = 0; while (flag != 1) { if (b == 1 && k != v.size()) { b += v[k]; k++; b--; } else { b--; } if (b == 0) { break; } if (b > a) { b = a; } sec++; } cout << sec << endl; int main() { int t; cin >> t; while (t--) { solve(); } return 0; } this code gives me timed exceed on second test can anything be done inorder to fix it ? |
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK