Hello Codeforces!
On Nov/19/2020 17:35 (Moscow time) Educational Codeforces Round 98 (Rated for Div. 2) will start.
Series of Educational Rounds continue being held as Harbour.Space University initiative! You can read the details about the cooperation between Harbour.Space University and Codeforces in the blog post.
This round will be rated for the participants with rating lower than 2100. It will be held on extended ICPC rules. The penalty for each incorrect submission until the submission with a full solution is 10 minutes. After the end of the contest you will have 12 hours to hack any solution you want. You will have access to copy any solution and test it locally.
You will be given 6 or 7 problems and 2 hours to solve them.
The problems were invented and prepared by Roman Roms Glazov, Adilbek adedalic Dalabaev, Vladimir vovuh Petrov, Ivan BledDest Androsov, Maksim Neon Mescheryakov and me. Also huge thanks to Mike MikeMirzayanov Mirzayanov for great systems Polygon and Codeforces.
Good luck to all the participants!
Congratulations to the winners:
Rank | Competitor | Problems Solved | Penalty |
---|---|---|---|
1 | dlalswp25 | 6 | 205 |
2 | Ormlis | 6 | 207 |
3 | Tlatoani | 6 | 214 |
4 | yokozuna57 | 6 | 232 |
5 | peti1234 | 6 | 235 |
Congratulations to the best hackers:
Rank | Competitor | Hack Count |
---|---|---|
1 | racsosabe | 80:-17 |
2 | Elo | 33:-4 |
3 | peti1234 | 24 |
4 | AsunderSquall | 26:-7 |
5 | xiaofan7 | 25:-10 |
And finally people who were the first to solve each problem:
Problem | Competitor | Penalty |
---|---|---|
A | Geothermal | 0:01 |
B | SSRS_ | 0:04 |
C | Valera_Grinenko | 0:02 |
D | SSRS_ | 0:10 |
E | Akulyat | 0:38 |
F | Suiseiseki | 0:58 |
G | rainboy | 0:42 |
UPD: Editorial is out
Deleted
Hey I want to know why you got downvoted... You were just wishing everyone good luck. Am I missing something? I feel bad for you :(
Anything that's obvious, repeated and doesn't adds value and just adds an extra comment for the sake of it and just increases the time to read the comment thread gets downvoted mostly, and sometimes people do it just for fun as well to channel their frustration of a bad contest or something. I have a feeling this will be downvoted too, but that's all there's to it, the explanation you were looking for.
Don't worry we will upvote you eventually. Love from Sweden!
I have a feeling this is going to be a good one.
ohhh
road to cyan
No worries for the noobs then!
Road to cyan
I wish!
Congrats @keshavgarg
I got hacked swag3301 :(
Sad life
very sad bro very sad :(
cf predictor is showing something -200 for you lol.
rama798 you did it on purpose didn't you?
yes, you can check my profile lol
there is almost 10 days difference between the techno cup round and the next div 2 round .... plz if we can have some contest in between??
yes sir! how many contests you order?
I would like to order 2 contests without shitty implementation problems and pack it nicely into short statements. Strong pretests will be appreciated.
You needn't think about that in this much advance.. Mostly contests will pop up around 3-5 days before they will be held. And that much of advance notice is enough and there are many Coding Contest Tracker Apps to help you with tracking(Coding Schedule for example) if you need one.
.
congras, your programme gives the expected output :v
.
I wish I would do better in this contest. Hopefully ,I will do it.
Is it rated?
[Deleted]
he asked for contribution maybe..
contribution for what? like dislike system?
As a Monogon give me contribution
Edit: I'm getting scammed, rip
It seems like it didn't work out as you expected XD
too bad you had even asked for permission to use this in next round
Don't worry I planned ahead to get 69 downvotes(yep definitely),
As you can see, it worked out.
well its 70 don't worry i will make it 69
Again an educational round without any tester? What if we observe any issue with test case/problem explanation later during the contest? We still have around 19hrs, I guess we can have some testers and there feedback?
Why is he downvoted? He raises a fair point I think?
(Edit: his comment was downvoted when I wrote my comment)
Exactly, I was just talking about one of the possibility based on past educational round. Lets hope we see a healthy round today.
I don't think there would be any harm in having few testers, there are many yellow/red participants who participates in educational round, for them round will already be unrated. So we can maybe ask for volunteers? Even many rated participants would be ready to volunteer.
awoo what do you think? This will just decrease the chances of any actual issues in the problemset.
Seriously, why does it take a red's agreement to give this person the upvotes he deserves.
ratism is real on CF.
It's about the respect I guess towards the work put in to get to red !
+1 from my side.. We already witnessed(Round 682) what happens when something unorganised goes from tester's side. And this one is without them wholly.. Fingers crossed
Chasing CM dream...
Wish I would not lose my ratings.
And now you are GrandMaster. Dreams come true :)
Last two contest was horrible. Finger crossed this time
I think CF Round #683 was not horrible, what do you think?
Oh, My bad! I was talking about Round 684 and 682. Round 682 has a nice set of problems but went unrated! Thanks for pointing out blobugh
I just want to make my contribution to 0 from negative.
I know I may add more negative contributing from this comment but still I want to give it a try.
those who upvoted I really wanna thank you. But I think its not going to work. Anyways Good luck for today's contest.
If you really want to make your contribution >=0 in this post, I think you should comment few more comments in this thread. More the comments, more is the risk but more are the chances you will gain large contribution in this.
no I am not greedy. I just want my contributions to 0 from negative.
Lol, I must say that itself is greedy.
haha, you can say.
Seems like u achieved your mission.
yes... Thank you everyone who upvoted...
Now that's a nice way to get upvotes.
Please make my contribution from -1 to 0.
It's +1 now, Let's make it 0 again...!!!
hahaha make me atleast 1 please;)
It's +4 now, let's make it +1 again....!!!
Thank you guys for upvoting..
please make my contribution from 103 — 1 to 103
upvote and down vote should be logically. First time i comment and I just expressed my feelings, but why am i getting down vote? It makes me frustrated. But i realized, upvote and down vote means contribution for codeforces. Please, make me 0 contribution from negative.
Hey guys ,do check https://gameofcodes.herokuapp.com (Okay, I know its a promotion, but the whole site is for codeforces lovers, so I guess its okay)
Why So downvotes? I think dude has made a cool website, though it loads a bit late. But I think the UI is just awesome.
Glad you like it. Don't worry about the downvotes... it just motivates me to make it much cooler and make it more user friendly.
[Deleted]
You happy now?
[Deleted]
![ ]()
I actually upvoted here but....
have fun with -4 XD
All the best Goiss !!! Just making my contribution >=0 from negative.
how to make friends on codeforces?i have 0:(
u can click star but that will make the user your friend.it will not increase your count of friends.for that somebody needs to click on the star of your profile
This comment section is a bit weird...
Hope petya, vasya, or their friends aren't too confused.
Highly unbalanced round :(
Definitely losing lots of rating, can I get some contribution upvotes? :((
Better try solving the problems instead of wasting time here
about -47
B and D should interchange their position :)
D is a stupid problem.
The contest is still going on man! Calm down
These remarks just give away hints
maybe you are right, but i don't think calling a problem stupid gives any kind of hint.
Anyone who solved B but couldn't solve D would become biased after reading this, don't you think so?
no, i don't think so. But i will make sure not to make such comment during ongoing contest.
yaa I solved B but couldn't solve D I should have read above comment
Whats the trick to B? Solved A, C, D still couldnt figure out B.
problem E is very hard. and I think they should have switched places of problem c and b. D is a very interesting problem. Good luck everyone!
C < A < D < B
Something seems wrong with the official scoreboard, it is also showing for users having rating >= 2100.
You should've switched the C to B, D to C and B to D. Time penalties just killed my contest. And there comes very tough E so I can't even come back
Maybe C with B should have been swapped, yes. But B with D? Are you serious?
For me, formula for B wasn't that straightforward. And I also needed construction to get the idea is correct
D seemed pretty standard. I still don't know how to solve B lol
The order was the same for everyone, so you have only yourself to blame for your poor strategy choices.
This round is pure destruction.
Exactly! I solved D with no difficulty, but couldn't solve B.
How to solve D ?
Signal power assigned to some tower doesn't matter.
(nth fibonacci number)/ $$$2^n$$$
Educational rounds are always pure destruction for me for some reason
What is C ? Trollforces ? I want to ask authors that why would they think this problem to be worthy at a position for D2C
We estimate the difficulty of ER C as Div2B, not Div2C. Do you think that this problem is easier than Div2B?
Oh ok .. I never knew such a thing also existed. Also I liked the problem D. Thanks for the round once again.
How to solve D ??
Can anyone explain the answer for the first test case ? .. i even failed to understand the test case with 1 hours . poor me :(nth fibonacci * inverse(2^n). You can try brute force by recursion on some small numbers and check the pattern. The question is how many ways are there of choosing (only)odd numbers so that there sum is perfectly n.
These are the ways of arranging radio towers on different n.
The main idea is that lets say you want to cover the region of n blocks, then what you can do is take the 1 position and make the tower to have 1 power, take 3 position and put tower in the middle with power 2, take 5 position and and put tower in the middle with power 3, and so on.
So for a state with n position we get a nice recusive relation
In the end since we are required to print the probability which is equal to f(n) / 2 ^ n where 2 ^ n are all possible configurations and f(n) are valid configurations. Also remember this all happens under mod
Hi, I got that x/y will be f(n) / 2 ^ n and wasted a lot of time on that mod operation but couldn't solve. Can you please explain?
https://codeforces.me/blog/entry/78873 this?
******you used modExp(y, mod-2). why everyone used mod — 2.. I didn't understand.. can you please explain...*********
Rafiqul01 In this blog, you can see at the end of Fermat's Little Theorem, we get
inv(a)≡a^p−2(modp)
, substitute 'p' with the 'mod' number given and 'a' with 2^nJi_Kuai So for summary, I can remember this: (x/y)(mod p) = (x * pow(y, p-2))(mod p) right ?
Yes, also be careful at that p must be prime
Whoever made problem D, I love you. Fibonacci sequence popped out of nowhere. Could someone please share a solution to F?
Me:
"That's what we call a balanced problemset"
Nice DIv3 till D and DIv1 after D . If I am not wrong it seems (Div1 +DIv3)/2===> DIv2.
the gap between D and E is huge man
Solution for problem D: The probability of choosing any $$$a_1,a_2,\dots ,a_k$$$ is the same for all, $$$\frac{1}{2^n}$$$ as we have to chose those and not chose the others, so we just want to find the number of subsets of $$$1,2,3,\dots ,n$$$ that work.
Let's call this number of good sequences $$$a_n$$$. Notice that if $$$i$$$ is the smallest element that was chosen then it needs to cover $$$1$$$ while not hitting $$$0$$$ so the radius is exactly $$$i-1$$$. Therefore it covers $$$[1,2i-1]$$$ and we have to cover $$$[2i,n]$$$ without hitting $$$2i-1,n+1$$$. This is the exact same problem with $$$n-2i+1$$$ elements. Therefore, we have:
We can see that $a_0 = 1$ and $$$a_1 = 1$$$. So using this recursion we calculate $$$a_2 = a_1 = 1$$$, $$$a_3 = a_2+a_0 = 2$$$, $$$a_4 = a_3+a_1 = 3$$$ and $$$a_5 = a_4+a_2+a_0 = 5$$$. At this point we realize this is the Fibonacci sequence, and we can prove it with strong induction. $$$a_{2n-1} = a_{2n-2}+\dots + a_2+a_0 = F_{2n-2}+\dots + F_{2}+F_{0}$$$ from the hypothesis $$$F_{2n-3} = F_{2n-2}+\dots F_{2}+F_0$$$ so the above is just $$$a_{2n-1} = F_{2n-2}+F_{2n-3} = F_{2n-1}$$$. The even case is similar.
Therefore the answer is just $$$\dfrac{F_n}{2^n}$$$.
While solving, I didn't realize dp[N] = F(N).
I solved it with dynamic-programming.
Nice observation.
Thanks for the explanation.
Write a brute and find answer for 1 to 10. and observe the pattern, it's Fibbonacci.
The way I solved it is noticing the problem comes down to "Find the number of ways that you can express a number $$$n$$$ as a sum of odd numbers". Pretty well known this is found with the Fibonacci Series.
That's nice! I solved it in a more dubious way. My solution is based on the following observation: suppose the first active tower is x, then towers 1 -> x-1 and x+1 -> 2*x-1 are not active. Ok, now say we have N towers and we activate the first tower. Its signal power is obviously 1. This leaves us with the other N-1 towers and the initial problem, but with only N-1 towers. If we say dp[i] = the solution for i towers, then we can now state that dp[i] = 1/2 * dp[i-1] + something (1/2 is because we have to activate the first tower) Now suppose the first tower we activate is the second one. Its signal power is 2 and the first and third towers are not activated. Excluding these towers, we have the initial problem but with N-3 towers. So dp[i] = 1/2 * dp[i-1] + 1/8 * dp[i-3] + ...
Let's take some examples: dp[5] = 1/2 * dp[4] + 1/8 * dp[2] + 1/32 * dp[0] dp[4] = 1/2 * dp[3] + 1/8 * dp[1]
We can keep 2 partial sums, one for odd numbers and one for even numbers. When we calculate dp[5], we add it to the odd partial sum the following way: sum[odd] = sum[odd] * 1/4 + 1/2 * dp[5].
Why do u write "row" Instead of "consecutively" When u know prob A contains rows and cols
How to solve B? It was very hard for a B problem.
Say the sum is $$$S$$$, since we want them all to have the same number of blocks and the pile he chose ends up with $$$0$$$ they will have exactly $$$\frac{S}{n-1}$$$ blocks. So we always have to make $$$S$$$ divisible by $$$n-1$$$.
The only other condition is that $$$\frac{S}{n-1}$$$ is at least as large as all elements, otherwise since we can't take blocks away that pile would be larger.
Thus, if the maximum element in the sequence is $$$M$$$ the answer is just the largest of $$$M(n-1)-S$$$ and $$$(-S) \pmod{n-1}$$$
Thanks man , this s/n-1 thing came to my mind but was not able to develop on the thought .
What is the reason behind $$$(-S)(mod \ n-1)$$$?
To redistribute the blocks between $$$(n - 1)$$$ boxes, $$$S$$$ should be divisible by $$$(n - 1)$$$. $$$(-S) \bmod (n - 1)$$$ is the smallest non-negative number that, when added to $$$S$$$, makes it divisible.
Note that in this case, $$$\bmod$$$ is the mathematical definition of the modulus operation, in some languages (in C++, but maybe in some others as well) the standard modulus operator doesn't work that way (it will not produce a positive result if $$$(-S)$$$ is negative, but $$$\bmod$$$ in mathematics always produces a non-negative number), so you have to add $$$(n - 1)$$$ to the result of this expression to handle it, if the result is negative.
The idea is that if we can use the minimum value of the array to make every other value equal to each other ,then we can do the same for every other $$$i$$$. Let $$$mn$$$ be the minimum value in the array and $$$mx$$$ be the maximum. Then we need to calculate the sum of differences between $$$mx$$$ and every other value different from $$$mn$$$, we can call this value $$$s$$$. If $$$s>=mn$$$ then the required number of blocks will be exactly $$$s-mn$$$. Otherwise, we need to verify that $$$mn-s$$$ is divisible by $$$n-1$$$. If $$$(mn-s) mod (n-1) = 0$$$ then the answer is $$$0$$$, otherwise it will be $$$n-1$$$ minus the remainder.
Just make the sure you can satisfy all the conditions if you pick the box with the smallest number of balls. Because that box is the one with the maximum constraints. Then the other boxes will automatically satisfy the conditions because they will have lesser constraints than the smallest box. To satisfy the smallest box, calculate how much extra balls you require to make every box other than the selected box have the same number of balls i.e. the max.no. of balls in a box.
If the req no. of balls is less than the balls you have, just make sure that the extra balls are divisible by (n-1)
The problems A-D were very good and I enjoyed solving them.
But why sudden steep increase in difficulty for E,F,G
(Looked like Div0.5).
Solved E in $$$O(n^3)$$$...
how ?
Just see the last problem of this editorial
why do you comment about this before finishing open hacking period....
some guys might hack your code ... hope you for surviving..
After Hack phase, all successful hack tests will append to system tests, so my comment doesn't change anything xD. By the way, I wanna know whether is a right way to brute force or just luck
In fact, i submit hack data to your code.. but even though submitting worst test case, your code is not hacked..
i don't know why
Maybe the magic of instruction set optimize...
Yes, that might be true
Has someone solved e using ST with arithmetic sequence? I didn't manage to debug it in time.
Actually, instead of ST, you can use scanline. 100792298
Actually, I like problem B. But I didn't like why the arrangement is A — B — C — D instead of A — C — D — B (More precisely, B is harder than A, C, D because the idea not the straightforward one rather than A, C, and D). Since the target of contestant is Div. 2 user, I think put B in the second problem wasn't a good idea due to the idea is "more cool" than C and D.
any ideas what the 8th pretest for problem E is?
It would be better if you would have even allowed $$$O(n^2 \cdot logn ) $$$ solutions in problem E :(
We have written some $$$O(n^2 \log n)$$$ solutions for E, and they pass. Unfortunately, several participants even squeezed $$$O(n^3)$$$ with a lot of optimizations, so perhaps we should've left the constraints as $$$n \le 5000$$$. What is your solution?
I came up with this: iterate on leftmost of the 2 ranges, and initially map each input boundary to leftmost author. Then run a 2nd loop for 2nd author from right to left and keep removing intervals from left interval and move to right interval's DS. But that would required me to use lazy propagation which is very slow. I think with some smart work, it can be done without lazy propagation? or does the solution approach completely differ from this one? Time Complexity would be O(N^2 logN)
PS : Some N^3 solutions still managed to pass I believe. Also what do you think, would a time limit of 2.5 secs might have been better?
My solution is the following:
Let's look at two edtiorials as segments $$$[x, x + k - 1]$$$ and $$$[y, y + k - 1]$$$ ($$$x \le y$$$). Suppose there is a guy who wants to listen to problems $$$[l_i, r_i]$$$. Let's look at the centers of these three segments. If the center of the segment $$$[l_i, r_i]$$$ is closer to the center of $$$[x, x + k - 1]$$$ than to the center of $$$[y, y + k - 1]$$$, then the guy should go to the first editorial, otherwise — to the second editorial. It means that if we sort the participants according to the values of $$$l_i + r_i$$$, the prefix of them will go to the first editorial, and the suffix — to the second editorial.
There are different ways to continue this solution, but perhaps the most simple is to build prefix sums to answer the query "the sum of $$$a_i$$$ on some segment of participants if they go to an editorial starting with problem $$$x$$$" in $$$O(1)$$$. Then we just iterate on the prefix of participants that go to the first editorial, and find the best editorial for the prefix and for the suffix in $$$O(n)$$$.
Wow! Centers of the segments is brilliant! I wrote exactly that but tried some weird comparators. Nice problem!
Iterate for the range $$$ [l,l+k-1] $$$ of the first author.
For each $$$ l $$$, iterate for the range $$$ [r,r+k-1] $$$ of the second author, where $$$ r >= l $$$.
Whenever change range $$$ [r,r+k-1] $$$ to $$$ [r+1,r+k] $$$, remove the participants who will now prefer reading editorials from the first author's range. (They won't see editorials again from the second author for each $$$ r' > r $$$)
Maintain 2 segment trees, each having lazy propagation. Update answer by $$$max( ans,Query1(l,l+k-1)+Query2(r,r+k-1))$$$.
Participants having $$$ l_{i} = l $$$ will permanently join the first author for each $$$ l^{'} > l $$$, so update the segment tree accordingly.
Reset the segment tree of the second author.
98943451 it didn't even use the simplest optimization that iterates j from i+1 :(
same with this https://codeforces.me/contest/1452/submission/98975634
Solved problem D by finding pattern from sample test cases.
Please give One editorial for Two editorial!
Solving E be like...
What sort of optimizations in Problem E for passing O(n^3) solution ??
Just some pragmas nothing else: code
I really hope somebody finds a hack to these solutions cause its really annonying T_T
My solution for B,
Main observation is, If we empty any box the total number of blocks should be divisible by (n-1). Since we cannot remove any blocks we should add some blocks and the sum of all blocks should be divisible by n-1, so we will add some X blocks such that the sum of all blocks will be divisible by n-1. In this case each box will have (initial sum of blocks + X) / (n-1). If this value is greater than or equal to maximum blocks holding box, this is the answer.
But if this value is less than the initial maximum blocks holding box(say MAX), then we cannot arrange equal number of blocks in all boxes. so in this case it is optimal to have that MAX blocks in all boxes.
I have faced problem submitting D in last 7 minutes of the contest.Is there anyone who faced the same problem? Or it was just bad luck of me.
I felt B was easier than D. I don't know, I just was not able to see the Fibonacci pattern and delved deep into the combinatorics realm.
nvm
I don't think hacking in Educational Rounds gives you any extra score.
nvm
You don't gain anything for hacking in an educational contest.
Can someone explain the logic behind using fibonacci pattern in problem D
I so much wanted to solve D. Solved it at once after seeing the solution. Damn man
What I don't like about D
A lot of people solved it by the "notice the pattern" style without understanding anything about the problem itself. I don't think it is acceptable for the D problem
Also surely B was more difficult than C but that is less of a problem
what is proof of using fibonacci pattern in problem D
This guy here gave a proof
Thanks :P
No idea actually. I solved it this way
Just consider the leftmost city . If it is lit (p=0.5), the answer is f(n — 1) If it is not, then neighboring city has to be lit up and then it will also cover the third city
So f(n) = 1/2 f(n — 1) + 1/8 f(n — 3) + 1/32 f(n — 5) and so on...
Then I observed that it is just recursive formulae f(n) = 1/2 f(n — 1) + 1/4 f(n — 2)
Thanks :P
Can simply use substitution this way:
f(n) = f(n-1) + f(n-3) + f(n-5).... (1)
Replace n by n-2,
f(n-2) = f(n-3) + f(n-5) + ... (2)
Now from both (1) and (2), f(n) = f(n-1) + f(n-2) which is fibonacci recursive relation
Thanks :P
This happens a lot of time, especially with OEISable questions, kind of a shame that they miss out on nice problems but people are desperate to do questions during the contest (ofc I also used to do that), and besides that, I think being able to observe pattern is smart too, so it's acceptable imo.
I thought about OEIS kind problem too while writing the comment . Thank god it was not easily googlable this time.
Wasted more than an hour debugging G only because of some extremely stupid mistakes. I can't believe how foolish I am. Really wish I could code more accurately =(
In the problem D, everyone used modExp(y, mod-2). why everyone used mod — 2.. I didn't understand.. can you please explain...
to calculate multiplicative modulo inverse.
You want y^(-1) so that y * y^(-1) == 1
Fermat's little theorem says that if m is prime and a is not divisible by m then a^(m-1) == 1 mod m, then you can see this as a * a^(m-2) == 1 mod m, so a = y and a^(m-2) = y^(-1)
And using binary exponentiation you can calculate it fast:)
You can read more about it here https://codeforces.me/blog/entry/72527
Very unpopular and complicated solution for D:
Any tower will cover only odd number of points. So lets say we decide to choose $$$k$$$ points and the number of points spanned by $$$i^{th}$$$ point is $$$y_i$$$. Now we just need to solve for number of solutions to the equation $$$\displaystyle\sum_{i=1}^{k} y_i = n$$$ , where $$$y_i = 2x_i + 1$$$ and $$$x_i >= 0$$$. It transforms to finding the number of solutions to the equation $$$\displaystyle\sum_{i=1}^{k} x_i = (n - k)/2$$$ , which is given by the formula $$$\binom{x+k-1}{k-1}$$$ where $$$x = (n - k)/2$$$ and parity of $$$n$$$ and $$$k$$$ is same.
The final answer would be just the sum of all values from $$$k=1 . . . n$$$ divided by $$$2^n$$$. Total time complexity would be $$$O(n*log(mod))$$$. Submission Link
Thnx a lot :)
I was doing the same, was not able to come up with the combination formula.
I was thinking that i am the only who make it overcomplicated this way.But good to see your comment.
Proof that your formula indeed calculates fibonacci numbers
Although in a way, your solution is a proof of a different way to calculate fibonacci numbers because your solution is a different way of thinking about some problem for which the answer is fib(n)
in question A.Robot Program ,it was written that not more than 2 or more commands can be preformed in A ROW,so why test cases are made for rows and columns.
They meant no two same operations can be performed consecutively
Why don't this (Problem B) give TLE ?
The above solution uses the
O(N log N)
approach (multiset takesO(logN)
for finding, deleting, and adding an element), which easily passes in 1 second under the given constraintswhat is the dp approach for D?
write a recursive solution to find nth Fibonacci number and memoize it.
fibonacci?.. I was solving it 40mins through combinatorics while there was such a simple solution:(
We can observe through the statement that we are supposed to find the number of ways in which n can be represented as the sum of odd numbers.
We can see that from the below observation:
Now, if there is any tower with power $$$P$$$ then it can provide signal to the right $$$P-1$$$ cities and the left $$$P-1$$$ cities and to itself. So, each such tower will provide signal to $$$2P-1$$$. Also, note that each city should get signal from exactly one tower. Consider if choose x cities with each having power $$$P_{i}$$$ then we have,
$$$n={\displaystyle \sum_{i=1}^{i=x}(2P_{i}-1)}$$$
Using the above observation, we can easily deduce that we are required to find the number of ways in which n can be written as the sum of odd numbers. Now we can easily check the probability of every single case is $$$p=\frac{1}{2^{n}}$$$ and x = number of ways to represent n as the sum of odd numbers, we get final answer as $$$xp$$$. Rest is just left to use MOD operations wisely to obtain the final answer
To find the number of ways in which n can be represented as the sum of odd numbers uses the dynamic programming approach.
Base cases are: $$$dp[0]=0,$$$ $$$dp[1]=1$$$
The recursive relation here is: $$$dp[i] = dp[i-1] + dp[i-2]$$$
Proof for the recursive relation:
(1) $$$dp[n] = dp[n-1] + dp[n-3] + dp[n-5] + ... $$$
Also,
(2) $$$dp[n-2] = dp[n-3] + dp[n-5] + ...$$$
Therefore, using (1) and (2), we get,
$$$dp[n] = dp[n-1] + dp[n-2]$$$
Hence, $$$x=dp[n]$$$ and $$$y=2^{n}$$$
P.S Don't forget to use the modulus operations wherever necessary.
https://codeforces.me/contest/1452/submission/98921672
https://codeforces.me/contest/1452/submission/98926330
quite similar solutions :D
In problem D , i didn't reduce the probability fraction to irreducible form , but it got accepted. Should this not affect the final output ?
Yes,it shouldnt make any difference because as much as I remember , the condition is that denominator and the modulo should be coprime and denominator is only the power of 2 in the problem and modulo is a prime no.... BTW , I hope you remember (x/y)%mod=(x*(1/y))%mod=((x%mod)*((1/y)%mod))%mod.
Which condition do you mean here :
" the condition is that denominator and the modulo should be coprime" ?
The condition for modulo multiplicative inverse
I think A,C,D were much simpler than B..... Its just my opinion
https://youtu.be/BauOvXZOmL0 I solved B using Binary Search , give it watch if you want to.
Nice one man..
Any ideas for problem G?
The main idea is the following. Consider some starting vertex $$$v$$$ for Bob. Bob can make at least $$$x$$$ moves from this vertex if there exists such a vertex $$$u$$$ that the distance from $$$v$$$ to $$$u$$$ is not greater than $$$x$$$ and the distance from any Alice's marked vertex to $$$u$$$ is greater than $$$x$$$. The rest is multi-source bfs + centroid + possibly binary search (there is a solution in $$$log^2$$$ and a smarter one in $$$log$$$).
Can anyone tell who is rainboy (sorry for unnecessary tagging)? I am just amazed to see his/her performance. He/She starts from last and does the most difficult problem which has only 5-10 submissions and then leaves the contest, whereas he/she could rank $$$1st$$$. He was an international master before and now just specialist. Does he/she do that on purpose or is there some other reason. P.S.- Rainboy ranked 6th by completing the last 2 problems. Rainboy ORZ
He is probably another Karan gujjar.
Please don't compare that shit with this guy. This guy is really really good. Was just confused of why he uses this strategy.
I guess his main focus must be competitions like IOI, ICPC, where speed isn't given that much of an advantage over problem-solving. So, my guess is that he starts with the hardest problems because those are the level of problems that you would expect in such competitions, and also he must not care about rating at all :)
Just now, a friend asked me what happened to Master purinliang. I said "What was going on?" and then he sent me some screenshots.
I took a look! Ouch! It turned out to be yesterday. There were five young people, all rating more than 1900 points, and two rating more than 2400 points. They prepare a round named "Educational Codeforces Round 98", and I am very glad to join it.
However, the Problem A using a confusing vocabulary "row". I think that "Wa! There is a chance to hack others!" I coded that
A "Wrong Answer" suddenly attacked to hit my face. Ouch! I was very careless and didn't dodge, Ouch! It is not good, I advise myself "Rat tail juice"(it means "Behave yourself" in chinese), and reflect on it, and stop making such cleverness in the future.
Ah, "Educational round" should be based on peace, coding ethics, and no hacking in the room! Thank you my friends!
Can someone help why my solution for problem B 98926905 got hacked.
Why did you use while loop that has cost you? While loop will cause time limit excedded
Yes, I should have given more thought while implementing this.
This part of the code highlights the flaw of your solution. Before you take a look at the explanation, see if you can find why there is a flaw.
Explanation: In this while loop, the incremennts keep running until the condition in the while loop is no longer satisfied. In most test cases, this while loop only repeats for a limited amount of times, so time is not a major concern. However, in the hack testcase, (n-1) * max is 2 billion, while sum is 3 billion. In order for (n-1) * max to be greater then or equal to sum, max would have to be incremented 500 million times to exit the while loop. When there is a total of 1000 cases of this type, there simply isnt enough time to increment the variable 500 billion times. (500 million x 1000 cases)
How this can be avoided: Be careful with while loops because the execution will never leave the while loop until the condition is no longer satisfied. If there is a possible case that could make that while loop run forever or run a very large amount of times, see if you can find a way to remove it. Here, a max function can replace the while loop (and thus fix this flaw).
Ok. I should have given more time while thinking about the solution. As soon as it passed the sample test, I immediately made the submission. I think it would have anyhow failed the system test. Also my logic has a flaw, I could have made a better solution. Anyway, Thank you for your explanation.
I have made a new submission. Is there a way to run my new code on the test which was used to hack my solution?
You do not need to worry about that, since all successful hack's test cases(including yours) are added in the test cases that is used for practice submissions.
Ok. I didn't knew about that.
How to solve problem B?
greedy
My Solution wasn't greedy at all. But yes greedy is another choice.
how to solve problem E?
It's soo much of wait for rating changes in rounds having 12 hours of hacking phase!
do comments add up for contributions ?
[Deleted]
It seems that I still have to wait...
They will change after system testing.
Err... Alright.
Isn't system testing already completed?
Its takes a little while for it.. I guess ratings would be done in a hour or so as per usual trends
When will the results of this round show in division 2 users rating..?
You may see it here https://cf-predictor-frontend.herokuapp.com/contestSelector.html
when the tuitorial come out?
When will the ratings gets updated ??
Looking forward to Rating changes & Editorial!
Hello, In question C)Two Brackets I am unable to understand why am I getting TLE for testcase #22, by looking at editorials I understand my approach could have been improved but as per my knowledge for test case #22, time complexity for my code should be O(n)(only for this particular test case),then why the error? https://codeforces.me/contest/1452/submission/98933235
In test case 22 the input may be of the form [[[[[.........)))))))), in your code when the else if condition of s[i] == ')' will become true, it will iterate the complete vector as there wouldn't be any '(' for each ')', your loop will run for each closing braces and hence the time taken would change drastically and complexity would become o(n²)
Five hours after system tests and still no rating changes. Keep waiting...
Instead of giving me rating they took my rating for last contest too :(
Lol, yeah i panicked for a second
Hey, I took part in the contest and was able to solve 2 questions. However, my rating hasn't updated. Neither has my contests page. Can someone tell me why?
SOmetimes it takes around 12 hours to update ,wait a bit
Okay, thank you!
how to solve b?
It's easy to know that the most candies are needed when the nephew choose the smallest $$$a_i$$$ and make the candies in the rest of the box not smaller than the biggest $$$a_i$$$. You can get a fomula and calculate it quickly.
Sorry for my awful English because I'm a Chinese :(
why i get tle in test case 20 of problem E
my submission : 99017296
logic
Where's the editorial
Auto comment: topic has been updated by awoo (previous revision, new revision, compare).
Reminder: please update ratings...
EDIT: updated :-)
Auto comment: topic has been updated by awoo (previous revision, new revision, compare).