Tutorial is loading...
Jury solution: 85699387
Tutorial is loading...
Jury solution: 85699884 Tutorial is loading...
Jury solution: 85699939UPD: $$$m<\min(a,b)$$$ is wrong, the right text is $$$m\le \min(a,b)$$$
Tutorial is loading...
Jury solution: 85700178 Tutorial is loading...
Jury solution: 85700334 Tutorial is loading...
Jury solution (Solution 1): 85700515Jury solution (Solution 2): 85700518
Tutorial is loading...
Jury solution: 85700669Feel free to share your approach here!
My first submission for problem A in C++ was
ceil(1.0 * n / 2) and got WA. Does anyone have any idea what is wrong?
Why the downvote? Same is written here
Because here 1.0*n is evaluated first, the result of which is a float value and the divison of this floating value with 2 (integer type) results in a floating value. Hence, there is no precision loss due to divison.
You have to use (int)ceil(1.0 * n/2), because large values will be in Scientific floating-point notation
Try n = 1000000000, it outputs "5e+008"
Thanks
alternative of ceil is == >> **(n+1)/2 ** it will also give you a same answer
For some reason, a lot of people use the ceiling and floor function for libraries. There are many ways to mess up when doing this. I personally find it a lot easier to just use the fact that programming languages round down when dividing. Thus, to floor a/b you can do
a/b
and to ceiling a/b you can do(a+b-1)/b
Totally true. I used ceil once in Problem A and it didn't get accepted. I was not able to solve A in that contest. Since then I'm never using ceil.
At situations like these it's best to do (n + 1)/2
Here's a trick for calculating ceil of (a/b). Just do (a+b-1)/b. No, need to confuse yourself with ceil functions.
I also got wrong answer same way...you can use (n-1)/2+1 for avoid ceil()..
See the link for better understanding Click here...
int ceil2(int a, int b) { int c=a/b; if(a % b ! =0) c++; return }
One should always point out that that's not the way one spells "Phalange" ;P
Dude, you lost the whole joke.
The whole point of the name is for fake identity theft. Spelling it right is not actually "right" (P.s if you are not friends fan, drop it)
You can use : double n; cin>>n; cout<<fixed<<setprecision(0)<<ceil(n/2);
1
99999999
5e+07
I don't like the problems which can be done without using functions or loops
Try adding and subtracting using loops then and wrap these loops inside a function.
I think you understood the comment wrongly.
Problemsetting might not be the job for you.
You are green and you think you know a dime about problemsetting.
It shows the message that "You are not allowed to view the requested page" when trying to access the jury solutions.
Pathetic and Confusing problem statement for problem B. Shitty Contest
For problem B I would have to agree the problem statement was pretty confusing, but others were fine.
ya the problem statement confused me too.. after getting the solution it was very easy
Yeah I had a hard time understanding how a shape spread in 2 rows in a calendar with x columns can be compared with the same shape spread in 2 rows in a y columns calendar
Link for the solution codes are not working right now ... please fix them.
Can someone elaborate problem D's editorial?
The idea is to fill out as many diagonals as possible, where each diagonal could wrap around the left/right sides. Filling in a diagonal increases each $$$R_i$$$ and $$$C_j$$$ by one. For a fully complete diagonal, $$$max(R) = min(R)$$$ and $$$max(C) = min(C)$$$, hence $$$f(A)=0$$$ if $$$k \% n = 0$$$. For an incomplete diagonal, you get $$$max(R) = min(R) + 1$$$ and $$$max(C) = min(C) + 1$$$, so $$$f(A)=2$$$.
what does this means "each diagonal could wrap around the left/right sides??
Wrapping around the left/right sides means that if the diagonal would go off the right side, it would continue on the left side. I think a visual example is the best explanation:
Step 0:
Step 1:
Step 2:
Step 3:
Thankyou so much.. got it now
i am still now getting...what if k%n is not zero
Thank you! This was very helpful than the editorial.
SO much better than the editorial. Thanks :)
How did you get that intuition tho? Wrap around diagonals seems a notch above any intuition I got. The closest I got to is filling out the closest diagonal stripe in the grid —
Only later did I realise that it was wrong.
The diagonals aren't really the important part here, it's just easy to construct that way. These matrices are equivalent:
Think of it like filling a chessboard with rooks. If you place the first rook at $$$(r, c)$$$ , then you are left with $$$n-1$$$ rows and $$$n-1$$$ columns open (this is equivalent to 1 row and 1 column with a sum of 1 and $$$n-1$$$ rows and $$$n-1$$$ columns with a sum of 0). Since we're trying to minimize the difference in max/min sums, it's better to place the second rook on an open row and column. This will leave you with $$$n-2$$$ rows and $$$n-2$$$ columns. Keep following this pattern, and you'll end up with $$$n$$$ rooks on the board.
So after filling in n rooks (as per the finding open column open row method), if k is greater than n, how would the remaining rooks go into the board? Or they could just be filled randomly?
You would treat the $$$n$$$ spaces that the first rooks take up as unavailable spots, then place the next $$$n$$$ rooks in the same way as the first $$$n$$$ where only 1 new rook per row and 1 new rook per column. The important part is that you don't place 2 on the same row/column when they're part of the same "rook group".
The following is not the way written in the editorial, but I have done it in my solution. Firstly, lets observe that if $$$k$$$ is divisible by $$$n$$$, the answer is $$$0$$$, and when it is not, the answer is $$$2$$$.
There are $$$n$$$ rows and $$$n$$$ columns. ($$$k$$$ % $$$n$$$) is always less than $$$n$$$. Thus each extra integer, can be fitted in these $$$n$$$ rows and columns.
Now, how to fit the integers?
What I did was first insert $$$1$$$s in indexes $$$[1, 1], [2, 2], ...., [n, n]$$$.
In the next iteration, I inserted $$$1$$$s in indexes $$$[1, 2], [2, 3], ...., [n, 1]$$$
Like this, we have $$$(k / n)$$$ iterations.
I had put the extra $$$(k$$$ % $$$n)$$$ 1s simply as if it was the $$$(k / n) + 1$$$ th iteration, and only the first $$$(k$$$ % $$$n)$$$ 1s need to be inserted.
My submission for reference: 85648287
I didn't understand how you put remaining
k%n
one's please explainWe put the ones in $$$k / n$$$ iterations, and thus the remaining ones will be $$$k$$$ % $$$n$$$. Note, over here the answer is $$$2$$$. The remaining ones should be lesser than $$$n$$$, because if not, then we could have added another iteration to use the $$$n$$$ ones. As the remaining ones are lesser than $$$n$$$, it means that they are lesser than the number of rows and columns. Thus, we iterate for the first $$$k$$$ % $$$n$$$ rows and columns, in the next iteration, and initialise that point $$$a[row][col]$$$ to $$$1$$$.
There is no need to do seperately for
k/n
andk%n
we can fill the matrix in only one loop going from[1,k]
Yes, but don't you think the implementation will go for a toss? I am not telling you that my solution is the best, just telling you from my perspective, I code a solution which is the easiest to implement.
That formular is wrong, isn't it? $$$f(A)=2(1^2+1^2)$$$
I implemented AC that as
It says f(A)=2. Which is the result of (1^2+1^2). Correct me if I got it wrong.
It says f(A)=4. Which is result of 2*(1^2+1^2)
Or what is the 2 good for?
No, he means to say that f(A)=2, which comes from 1^2+1^2, that's why the brackets. The brackets are not indicating multiplication.
I think B and C should have been swapped. Thanks for fast editorial though.
I think D was little bit similar to 1360G - A/B Matrix and thank you for a nice contest.
I actually copied some code from that problem when the answer is 0
I actually copied almost the whole code. See this submission 81245465 for problem 1360G - A/B Matrix and my submission 85681253 for problem D.
That's why i was able to do this problem otherwise it would be hard to come up with such algorithm during contest.
Little bit? Dude for k%n!=0 you just add one for loop and you get AC.
Wow man you have such a nice memory XD I think this is the third time I have seen you remembering similar old problems. No offence tho :)
pattern in questions!
I know it's too much to ask from anyone , but i will be highly obliged and grateful to the one who will look at my submissions of D to see why it fails to pass test cases . My submission link : https://mirror.codeforces.com/contest/1371/submission/85694260
testcase
4 7
your answer
correct answer
Thanks a lot man! i understand now . Have a great luck and wonderful day/night ahead ! :)
I up-vote this for your humbleness
Could E be solved, under the same constraints, if P was not prime ? I'm curious about it.
if $$$p$$$ is not prime, you should replace it with the minimum integer $$$k$$$ such that $$$k!$$$ is a multiple of $$$p$$$
upd: nvm, it's wrong
reasoning
the answers are such $$$x$$$ that some $$$P[i]$$$ can be chosen in $$$\geq k$$$ ways
you can prove that, if this condition is true, for $$$1 \leq y \leq k$$$, some $$$P[i]$$$ can be chosen in $$$y$$$ ways, so $$$f(x)$$$ is a multiple of $$$k!$$$
upd: nvm, it's wrong
Div2 rounds are now tending towards Div3! who else feels same?
May be it is because it was physics0523's first round that's why..!
No Actually u r an expert!! thats why
It's not about individual rating, just look at submissions on problems till E!, it is rare.
Question B should have been better explained
To be honest, felt like a div3. except the last problem. For others, no. of submissions is almost same as on a div3.
You can't just compare no. of submissions in a div3 contest and a div2 contest. In a div2 contest there are more high rated coders than in div3 contest. The expected rank of a 1500 rated coder in Codeforces Round 654 (Div. 2) was 4299, and his rank would be 2894 in the contest Codeforces Round 650 (Div. 3)
Problem is easy, coders are not very skilled, no of submissions are X. Problems are harder, coders are also better skilled, the problem might get a similar number of submissions.
I used this website to calculate expected ranks.
To compare the div3 rounds and div2 rounds, compare their problem difficulties, not no. of submissions.
In C's editorial shouldn't it be m<=min(a,b) rather than m<min(a,b)?
yeah, i am thinking about that. it should be m <= min(a, b)
Why can't someone who knows English go over the problems and correct bad translations? It's so hard to read these problems with so many out of place commas, and completely messy sentences.
Editorial Problem E1 You can find the value of f(x) by the following simulation:
First, let v={the number of enemies they have strictly less than x candies}, ans=1. Then do the following steps for i=x,x+1,...,x+(n−1). v=v + {the number of enemies they have exactly i candies} ans=ans∗v v=v−1
Is it just me or was this part not really that intuitive?
Yeah,
I still haven't been able to fully understand the Editorial of E1.
I understood the statement by seeing some solutions but the reason it works is still a mystery to me
Found a good explanation https://mirror.codeforces.com/blog/entry/79624#comment-654544
for a give n x we are calculating all permutations v = all value less then x we can always put all v values in first place x could always defeat these values and will become x+1 now in second position e can select v -1 as out of v we have already put 1 value at first place but, we can also put those values which are equal to x+1 thats why for x+1 we added v += the num of enemy that has exactly x+1 candies. so we should multiply our ans with this num thatis ans = v*(v-1 + k) where k is num of enemies that have exactly same candies as x+1 and v is numbver of candies less then x, and so on.
I did the same thing that's mentioned in the editorial for E1. But I am getting WA for test 5. Submission.
Can someone explain C with examples? And what tags do these types of problems come under?
Notice Second Type of guest always consume the one which is small in quantity. So if v > c then only chocolate will be consume by Type 2 guest or if c > v then only vanilla is consume and after consuming either the inequality v > c or c > v which one is there will still hold true. So if min(v, c) >= m then we can always allocate 1 cookie to each type 2 guests.
Thank you, that helps!
Oh man...Thanks a lot..! After going through so many comments I was finally able get something related to problem and helpful as well. Thanks again
Finally understood B, thanks!
At least provide some explanation for problem D. We can see the other's submission if we want to see code.
You have to note the pattern. I will explain this by an example.
For k <= n it is simple : We have to fill only along the diagonal.
For k > n :
One thing that is sure : Putting 1 along diagonal is always optimal choice to minimize the final ans.
Step 1. Fill the diagonal
Step2 .
Step 3. See the pattern
Step 4. We will repeat what we have done in step 2, and step 3 till we still some entry to fill.
Repeating pattern :
Repeating pattern:
And finally :
Trick that I use to print is r-c (or c-r) is constant for a particular diagonal.
Any reason for making problem C around the same difficulty as a typical Div2 A?
In D there should be either (1^2 + 1^2) or 2 * 1^2, not 2 * (1^2 + 1^2).
problem C was fantastic for me.I spended too much time for it.when I finded it's solution I just surprised.
First 4 problems felt more like div3 contest only maths and implementation kind. Or may be I am improving.
You are improving...
in Maths
How can you judge a problem without taking part in actual contest.
By solving it after the contest ends.
solving a problem after the contest is much easier than during the contest. Have a look at problem C, it seemed difficult to most of the people appearing for the contest but after upsolving they found that very easy.
NOT LOOKING AT THE SOLUTIONS BEFORE
Felt like giving an Aptitude test!
Yes, At least for the first 4 problems Never thought pattern recognition and printing will help me solve my firsts Div2 D problem :D
https://mirror.codeforces.com/blog/entry/79541?#comment-654173 This single comment has a better explanation for A, B, C than this editorial
Can Any One Explain me Solution of problem:E1? Because I am still not able to understand it through Editorial. Please Explain if You know .
How we can find the value of f(x)???
My reasoning was: Sort $$$a$$$. Fix $$$x$$$ $$$(1 \leq x \leq 2000)$$$. Lets see how many elements we can pick to be $$$P_0$$$ in a valid permutation. Find the last $$$i$$$ such that $$$a_i \leq x$$$. Then we can let $$$P_0 = a_0 \text{ or } a_1 \text{ or } ... \text{ or } a_i$$$. Thus there are $$$i + 1$$$ ways to pick $$$P_0$$$. To pick $$$P_1$$$ we do the same thing, i.e., find the last $$$i$$$ such that $$$a_i \leq x + 1$$$. Then we can let $$$P_1 = a_0 \text{ or } a_1 \text{ or } ... \text{ or } a_i$$$ except that we used one of these elements in choosing $$$P_0$$$. Thus there are $$$i + 1 - 1$$$ ways to pick $$$P_1$$$. Repeat this process for each $$$j < n$$$. If you get to some $$$j$$$ such that the number of ways to pick $$$P_j$$$ is divisible by $$$p$$$, then $$$x$$$ is not valid. Otherwise it is valid. The time complexity is $$$O(\max(a)n\log(n))$$$. This definitely won't pass E2 though.
Edit: My contest code (disregard the freq array, it is unused): 85694840
I have done the same thing as you. Can you tell me what is wrong with my code?
https://mirror.codeforces.com/contest/1371/submission/85673827
probably overflow? You never modded your ans variable, but it can be as big as $$$n!$$$
Lol you're right...was so close to solving 5 for the first time :(
Thanks for sharing your approach mate...idk why but was struggling to understand the editorial...I found your approach more insightful. Thanks. Appreciate it! :)
You can find the minimum x such that f(x) % p != 0, then you can do binary search on your same approach for maximum x. And print from minimum to maximum.
Yep that's the editorial's first solution for E2. The editorials $$$C_i(x)$$$ function is the number of ways to choose $$$P_i$$$ if the starting amount is $$$x$$$. I implemented it and it works in $$$O(\log(1e9)n\log(n))$$$ (~100ms).
During solving this question on practice. I just guessed(weak guess) that maybe the answer would be a continuous segment. So, did a binary search. Still, not understanding why it worked?
Its because of these two simple observations that the editorial states:
$$$1.$$$ For each $$$x$$$, for each $$$i$$$ $$$(0 \leq i < n - 1)$$$, $$$C_i(x) \geq C_{i + 1}(x) - 1$$$, and $$$C_n(x) \leq 1$$$.
$$$2.$$$ For each $$$i$$$ ($$$0 \leq i < n$$$), for each $$$x$$$, $$$C_i(x) \leq C_i(x + 1)$$$.
From $$$(1)$$$, its clear that if $$$C_i(x) \geq p$$$ at some $$$i$$$, then there must be some $$$j \geq i$$$ such that $$$C_j(x) = p$$$.
Since $$$p$$$ is prime, $$$p \mid f(x)$$$ if and only if $$$p \mid C_i(x)$$$ for some $$$i$$$ $$$(0 \leq i < n)$$$. I think this is called Euclid's Lemma.
Thus from $$$(2)$$$ it is clear that $$$f(x) > 0$$$ and $$$p \mid f(x) \implies f(x + 1) > 0$$$ and $$$p \mid f(x + 1)$$$. Therefore there will be a smallest value $$$mn$$$ such that $$$f(mn) > 0$$$, and there will be a smallest value $$$mx \geq mn$$$ such that $$$f(mx) > 0$$$ and $$$p \mid mx$$$ and each $$$x \geq mx$$$ is not good. Thus binary search works. The answer is just the range $$$[mn, mx)$$$.
I can`t understand the first condition.
suppose x = 3 and i be 2, then power at i=2 will be 5, so C(i,x) will give how many values are there less than or equal to 5, suppose this value is 10, out of this 2 have already been used at index 0 and 1 so value should be 8.
Now at i+1 we will have value 6 and then we will ask how many values are there less than or equal to 6, this will incude all the values less than or equal to 5 and the values equal to 6, let it be 15 (10+5(freq. of 6)), as now 3 value have been used value value here will be 12
so we have C(i,x) = 8 and C(i+1,x) = 12, then how is the above condition satisfied ?
Thanks a lot, for some reason I wasn't able to understand this via the official editorial. You saved me from a headache :P
Ha, thank you! Good explanation.
I'm trying to understand the editorial implementation now. But I can't figure out what the
bk
array means. Can someone give me an intuition?Can someone please help me with this submission for E1. It gets WA on test 9.
EDIT : I found the mistake. I was using set data structure earlier to get the count of elements less than or equal to $$$x+i$$$ which is wrong as it only stores unique elements and thus might give me wrong count values in case of duplicates.
.
how can one arrive to the approach used in problem D. I mean is it really too intuitive? If yes, then can anyone share similar problems for practice.
My idea was to flatten the board into a line of length $$$n^2$$$ and spread the ones "evenly" across the grid. That is, put a one at positions $$$0 \bmod n^2, (n + 1) \bmod n^2, 2(n + 1) \bmod n^2, ..., (k - 1)(n + 1) \bmod n^2$$$. Then you can easily convert the linear position to an $$$(r, c)$$$ coordinate by the formula $$$coord(x) = (x / n, x \bmod n)$$$. I didn't prove it rigorously, but it got AC: 85675022
I believe a similar technique can be used to solve this problem: https://mirror.codeforces.com/problemset/problem/1360/G
Thank you gentleman for this brilliant approach, now I am wondering how to prove and why this works. If possible can you please elaborate? Thanks a lot.
One. No square will be hit twice using this method, and all $$$n^2$$$ squares can be hit if needed (i.e. when $$$k = n^2$$$).
Proof: Since $$$\gcd(n + 1, n^2) = 1$$$ (easy to show, I hope you can figure it out), the method will hit exactly $$$\frac{n^2}{gcd(n + 1, n^2)} = n^2$$$ before returning to its initial position (0), so the claim holds. This formula follows from a theorem of group theory which states that for any positive integer $$$k$$$, for each $$$x \in \mathbb{Z}_k$$$, the smallest integer $$$d$$$ such that $$$d \cdot x \equiv 0 \pmod{k}$$$ is $$$d = \frac{n}{\gcd(x, n)}$$$. An equivalent way to say it is $$$d$$$ is equal to the number of distinct elements in $$$\mathbb{Z}_k$$$ you get by repeatedly adding $$$x$$$ to itself modulo $$$k$$$. This theorem appears surprisingly frequently on Code Forces for some reason (probably due to its relation to cycles and permutations).
Two. I'm still not sure how to rigorously prove that this method minimizes $$$f(A)$$$ ... Im guessing it has to do with the fact that also $$$\gcd(n + 1, n) = 1$$$.
Shouldn't it be $$$m \le min(a,b)$$$ for problem $$$C$$$?
In E2 for solution 1 :
"if C_i(x) exceeds p, then there will be some C_j(x) = p as C_i(x) decrements by at most 1".
Why is this necessary that some C_j(x) will be equal to p?
what if C_i(x) does not decrease but only increase? Can someone explain?
It has to decrease towards the end. If there was no constraints on choices at each turn and you had 5 options you end up with 5*4*3*2*1 choices. The constraints can never increase the number of choices for any turn but can reduce them so any 'good' x will ensure that you never have p or more choices on any turn.
Cn(x) has to be one bcoz total n choices. So,if some c_i > p and each c_j can atmost decrease by one then p+a....p.....1
The problems were wonderful. I loved them all.
However Ruby 2.7.1 (which was upgraded from 2.0.0 recently) is too slow on Codeforces. My O(1) (I mean, O(t)) solutions don't pass! https://mirror.codeforces.com/contest/1371/submission/85638755 Same code with same input passes in 150ms on Macbook Air and 75ms on AtCoder!
It seems that any Ruby2.7.1 submission takes 900ms at least. (Even if 1 line do-nothing code) So I guess Ruby2.7.1 on Codeforces has somewhat wrong settings.
And I found that previously passed code makes TLE now with Ruby2.7.1.
Please let me know if any better place to report bugs to Codeforces. Thanks!
Shouldn't it be m <= min(a,b) in place of m < min(a,b) as written in the editorial
Yes
For all those who want to understand how the solution for D is working, have a look at the comments of my code.
I can't understand the solution of C except the base condition n + m <= a + b. And how to think solution of this kind of problem, I tried different types of conditions but couldn't unite them.
Second type guests always choose fewer remaining type of cookies out of 2 types of cookies, so after they choose, the fewer number of remaining cookie is always reduced by 1. First type guests will not get angry if at least 1 cookie left, so the best thing to do is to put them on the back burner.
The contest was mostly logic based for question A to E1 and not much related to algorithms and data structures.
In problem E2 (Asterism), after we have calculated b_i, how are we able to find all the "good" x's in linear time?
Your algorithm for comprehending D is funny, Mr physics0523 ;P
For the whole round, I thought that in problem B, we have to count only one pattern for the row that completely divides the total number of days.The problem statement could have been written more clear.
still can't solve C :( if we call type 1 guest before type 2 guest then it won't decrease min(a,b) right? but in editorial
if there is a type 1 guest before a type 2 guest, the type 1 guest have a possibility to decrease the value of min(a,b) unnecessarily
If a = b and we call two guests of type 1, they will decrease the minimum of a and b.
Yes,this statement is conflicting. You can understand it by realising that at any moment,type 1 guest tries to eat the cookie which is more in number and type 2 tries to eat cookie which is less in number.If number of cookies are same the type 1 eats chocolate cookie and type 2 eats vanilla.
got it, tysm! we invite type 2 guests first because they take minimum of vanilla and choclate and in the end we invite type 1 guests and check if we have required remaining dishes.
This statement is genius! Thanks
I'm not sure whether this was mentioned before, but there is a DP solution to E1 which generalizes to E2. I am going to present a handwavy explanation of it:
85709850 Here, dp[i] denotes the number of valid permutations of the i smallest elements. From there, we want to insert a new element in these permutations, which does not make any of the existing duels worse, as our candies are monotonically increasing, so we just find the number of positions, where we can put the new element. If we had x candies at start and our new duel is the k-th one, then we will have x + k — 1 candies, so this must be at least the new amount of candies.
Now moving on to E2:85708674
Knowing the recursion from the dp, we can now see that if we have too few candies to win a duel, f(x) is 0, and if we have at least as many candies at start than the p-th smallest enemy, we will also have trouble, because that multiplies our dp by p. So we can find the min and max candies easily, and now we just want to quickly decide whether any of our other products are zero. The parts in the dp product before the p-th smallest element cannot be divisible by p, as they are positive but smaller than p, so we just take the elements from the p-th to the n-th and see whether they give a zero residue with p, granted that we have less candies than them when starting the fights (this follows from the enemies being sorted and us having at less candies than the p-th smallest enemy). This can also be done linearly.
E1, "Yuzu should have at least $$$m-n+1$$$ candies initially to win all duels."
Isn't that wrong? Having that much candis garanties that not all duels get lost, but to garantie to win all duels Yuzu must have $$$m$$$ candies. Since all a[i] can be equal $$$m$$$.
I mean, a[] is not a permutation or somehow else pairwise distinct.
bro see my solution for that problem it is easy to understand.
I did not solve it because I was not able to come up with formular to calculate f(x) for any fixed x. And, honestly, I am still not sure about that after reading the editorial.
:D hmm editorial is not good this time
Agreed, they did not explain the solutions well, they just wrote the pseudo-code for the problem.
Btw, I solved E1 in contest with basic principle of counting, for a fixed x, I counted no. of ways to fill 1st place * no. of ways to fill 2nd place and so on up to n places. My submission 85691626
If you have $$$m$$$ candies, you can definitely win all duels. What the author meant is this:
Let $$$x$$$ be the smallest number of candies you need to guarantee a win, then $$$x$$$ $$$\geq$$$ $$$m - n +1$$$. Had it been less than that, you'll have maximum $$$m-n+n-1$$$ candies against an enemy with $$$m$$$ candies.
Ok, what he meant is "Yuzu should have at least $$$m-n+1$$$ candies initially to not loose all duels."
Having m — n + 1 candies obviously does not guarantee winning all duels. eg — 5 5 5. Maybe, he meant that if we have candies less than this, then we are definitely going to lose.
Hi! By at least it means that any x below this and we're certain that f(x) = 0, so we don't need to check below that. It's not actually necessary to do this if formula for finding f(x) handles all cases tho.
In tutorial of C it should be m <= min(a,b) instead of m < min(a,b) for answer to be "Yes".
The test cases for E1 were such that I got a TLE when I solved in O(n*n*logn). Till today I thought log(n) does not make a difference. Got to learn something from the question.
My O(n*n*logn) solution passed well within the time limit 85702061
I think I have done the same thing. If possible could you give it a look? https://mirror.codeforces.com/contest/1371/submission/85691445
ash_vs_ash you are passing vector to function search() by value, therefore it is taking extra O(n) in every run and maybe that is why you're getting TLE. Try passing vector by reference to your function.
It worked like a charm. Thanx man.
Why am I getting WA on test case 6 of E1: 85714673
UPD: Fixed it
Can anyone please tell me what is wrong with my code for E1?
https://mirror.codeforces.com/contest/1371/submission/85673827
This is ecnerwala's solution for Problem D, can somebody help me in understanding how this solution works and what was the intuition behind that :)
It's the same diagonal construction as the editorial, but computed in a different order. For each cell, we compute which diagonal it's on and use that to decide whether it should be set or not.
This editorial is so hard it needs another editorial. Seriously, it was easier for me to solve problems than to understand this, not even saying anything about jury code quality. Some standards for writing editorials are needed.
I think it should be forbidden to have editorials in the form of pseudocode or formal algorithm description. I read editorials to understand how to arrive to the solution. If I want a formal description, I can just open anyone's submission
Pseudocode might be fine, if it is easier to read than actual code. The actual solution must be present anyways. What you might need is a system of "tips", that describe a way of thinking that could lead you to the solution.
Unfortunately, most of the time this is not the case and we see "just do this" or "we can prove that this works" types of arguments. Even just checking that a thing works might be of little value for me, because during contests you are not checking solutions, you need to come up with one.
binary search solution of E2
85716743
Hello, can anyone tell me how long we have to wait to see the change in our rating, system checking is done hours ago
they have been updated
just now I think thanks man
If you prefer video explainations, I go over everything (except a rather handwavey description of E2) at the end of my screencast of the round.
Can anyone please explain how this solution works for 1371E2 - Asterism (Hard Version). Thanks in advance.
85678389
I have a proof that the solution must be a contiguous sequence of numbers here: https://mirror.codeforces.com/blog/entry/79624?#comment-654797
He found the min and max numbers of the subarray, then printed every number in between.
It seems that while I used binary search to find the maximum bound of the subarray, he found a cleverer way just using a for loop.
I have an interesting solution for E2 using binary search.
It relies on the fact that the answer will always be a contiguous sequence of numbers. I have a proof of that fact below.
85713453 (find minimum value in easy O(N), binary search to find the max value that works, print every number in between).
Proof:
I also came up with a similar idea when upsolving, code with brief comments: 85718984
The upperbound is the largest number that never has $$$\geq p$$$ options, and every greater number will surely hit $$$p$$$ options "on the way back down" as they run out of options
Thanks. That really helped.
My solution and explanation for 1371E2 - Asterism (Hard Version)
The number of permutations for a given $$$x$$$ can be written in:
Since $p$ is a prime number, in order that $$$f(x)$$$ cannot be divided by $$$p$$$, we must ensure that $$$(\sum_{j=0}^{n-1}a_j\leq x+i)-i<p$$$ holds for every $$$i$$$. And in order that there is a possible permutation, we must ensure that $$$(\sum_{j=0}^{n-1}a_j\leq x+i)-i\geq1$$$ holds for every $$$i$$$.
Proof: Let's denote $$$(\sum_{j=0}^{n-1}a_j\leq x+i)-i$$$ as $$$g(i)$$$. We can find that, since $$$\sum_{j=0}^{n-1}a_j\leq x+i$$$ never decreases, so if $$$g(i)$$$ decreases, it can decrease at most $$$1$$$. Another observation is that $$$g(n-1)=1$$$. So if there is $$$i_1$$$ such that $$$g(i_1)>p$$$, there must be $$$i_2>i_1$$$ which satisfies $$$g(i_2)=p$$$, which makes $$$f(x)$$$ divided by $$$p$$$.
So the problem is now: how many $$$x$$$ are there that satisfy
Since $g(i)$ increases with x, the answer must be a continuous segment $$$[lo..hi]$$$.
Now we sort the array $$$a$$$ in the ascending order.
For $$$lo$$$, we have
For $$$hi$$$, we have
So the final answer is the segment
Code: 85684812
I can't understand the last two steps of your solution.Why Why does this formula work ? ∀i,hi+i<ai+p−1⟹hi<min(ai+p−1−i)
$$$\forall i, hi+i<a_{i+p-1}\implies\forall i,hi<a_{i+p-1}-i\implies hi<\min(a_{i+p-1}-i)$$$
I get it! Let cnt[x] be the amount of number which is equal or less than x,then we have ∀i,0<=i<n => cnt[x+i]-i<p => cnt[x+i]<p+i => x+i<a[p+i-1] => x<a[p+i-1]-i => x<min(a[p+i-1]-i). Thanks for your solution!
anodiebird How did you come up with,
x+i<a[p+i-1]
, steps before this one are clear. Can you please elucidate this one?⑴ x+i<a[p+i-1] => x<a[p+i-1]-i ⑵ a+b<c => a<c-b If you look at these two equations,you will see both of them are the same form,in the first equation I just change the position of i,in the second equation I just change the position of b.
anodiebird My doubt is that how did you transition from
cnt[x+i]<p+i
tox+i<a[p+i-1]
Because we have sorted the elements of a[].If index i begins from 0,then we can see cnt[a[i-1]]=i,and you can deduce that p+i=cnt[a[p+i-1]].So let's substitute that into our expression:cnt[x+i]<cnt[a[p+i-1]] => x+i<a[p+i-1] => x<a[p+i-1]-i
If author's approach for problem F is unclear, then you may check my solution. 85721976 Imho problem F is the only problem that I've found interesting in this contest.
It is probably because it's his/her first contest but the editorial solutions to D and E1 are the worst. There is no reasoning/intuition given whatsoever. Please take it as constructive criticism.
My solution for problem F : 85724126
My solution to 1371F - Raging Thunder
Helping information
Obviously, this is a segment-tree problem. Then what do we need to maintain in each node?
In my implementation, the following information is maintained:
Then the answer to the query within a node becomes $$$\max(hi, ll, rr)$$$.
With such information, node combination and node flipping becomes easier and clearer.
Node flipping
Node combination
My code
85729867
why i am getting run time error, i am unable to find that?
include<bits/stdc++.h>
using namespace std; int main() { int t; cin>>t; while(t--){ int n,k; cin>>n>>k; int res[n][n]; memset(res,0,sizeof(res)); if(k%n){ cout<<"2"<<endl; } else{ cout<<"0"<<endl; } int p=0; int q=0; for(int i=0;i<k;i++){
}
You set
res[p+1][q+1]=1
whilep+1
can ben
.What obfuscation software was used for the jury solutions? It is certainly very effective.
.
Invalid testcase. 8 is not a prime.
Can someone please provide a rigorous proof for Problem C as to why the order of guests where first all type 2 guests come and then type 1 guests come, is the most efficient ? I could not understand the explanation in the editorial.
I don't have a rigorous proof but you can think in this manner that guests of type one can always adjust to any kind of case whether only vanilla,chocolate or both (provided the number of guests of type ones is less than equal to the total number of cookies) so our number of type of cookies is independent of guests of type one.
It's not so for the guests of type two since they always choose the lesser type of cookies so if you feed the guests of type one before guests of type two it's going to be less optimal.(more chances of failure of satisfying the condition. Our problem asked to print yes even if a single situation could allow all guests to finish them off so always looking for most optimal way)
Thank You I think I get it now
Check out the video editorials:
E1. Asterism
D. Grid-00100
C. A cookie for you
B. Magical Calendar
A. Magical Sticks
Can you please make a video on E2
Are you color blind?
No
During the contest, I misread the question B as the total number of shapes of length n one can get if for any block, there is at least one block that shares one side with that block, thereby removing the problem constraint of n consecutive days. I still haven't been able to come up with any solution! Could anyone help with that?
UPD: Got it
What is wrong in my code for Asterism(Hard version) problem, I mean I am getting WA on test case 11, can someone help in finding the wrong logic that I am using in my code https://ideone.com/iUJnps
Are the ai values in E1 and E2 distinct or can some of them be the same?
Values can be same
No idea if this is mentioned before but I think there is a much cuter solution for F.
Notice that the balls are seperated by <> only. We only need to store leftmost, rightmost and longest distance between <> in a range. For the reverse it is just ><.
code: 85723638
Thanks! I was able to solve this problem with your idea.
By the way, I noticed that you use a MAX/MIN template for multiple elements. You don't actually need that since the following is valid in C++
x = max({a,b,c,d....})
(We just need to use {} for multiple elements)Or is there some other benefit that I don't know of?
I didnt know that was valid syntax .-.
I am a newbie Can someone explain me ( in problem D ) Why is this line included in the Jury solution ** arr[i][n]=0;** Thanks in advance
It has been used for string termination. This may help you.
Got it , I don't need to do that if I am using an Integer array right ?
Yes
Thanks a lot brother
Here is my approach and explanation for E1[problem:1371E1]
As Yuzu starts with
x
candies, we know the number of candies in each position of the array, i.e,x+1,x+2.....,x+n
. This means atith
position withi
starting from 0, the number of candies at that position must be strictly less thanx+i+1
.Sort the array and iterate from the back. Let
m1
be the maximum number. Now, how many positions canm1
occupy? It isx+n-m1
asm1
can only occupy positions having candies greater thanm1
.Now, let
m2
be the next(second maximum) number. It can occupy positionsx+n-m2-1
. We subtract 1 as one of the positons is already occupied by the maximum number. Similarly, form3
it will bex+n-m3-2
and so on.So, for
ith
number(array[i]
), the positions it can occupy isx+n-array[i]-(n-i-1)
. If the number is less than x, then we have to subtractx-array[i]
as the number of candies cannot be less than x, hence the number of positions it occupies will bex+n-array[i]-(n-i-1)-(x-array[i])
.On simplification, the number of positions for
array[i]>=x
isx-array[i]+i+1
and forarray[i]<x
isi+1
. or simplymin(x,array[i])+i+1-array[i]
.Now f(x) is simply product the positions the numbers can occupy. 85781407
If someone has a simpler explanation for this approach, please let me know
for problem 1371E1 — Asterism (Easy Version), i am doing same as stated in editorial, but still getting TLE. Is it because i am using Python 3 ? here is my solution Please help.
I guess no, there are many Python3 accepted solutions if you see the rank list
Why the statement on the tutorial of 1371E2 that once f(x) is divided by p,then f(x+a) is divided by p too is right?
Alternative approaches to ceil() is a blog post about the discussion on Problem A. I hope you find this useful.
https://mirror.codeforces.com/contest/1371/submission/85805079
https://mirror.codeforces.com/contest/1371/submission/85805620
The test case 2 is failing in both the solutions because the "jury" is changing it's answer in the second answer. In the first approach, it says that the answer for testcase 14 is 4 but in the second solution, it says that the answer is 0.
Why is this happening?
In problem E(hard version),I'd like to ask the conclusion "It's easy to see, that there should be max(ai)−n≤x≤max(ai) to have f(x)≠0 and f(x)≠n! (they are both divisible by p)." mentioned by the author. How to deduce it? While in Solution 1, though the author doesn't mention it, he uses this trick in bucket sort. So I am eager to know about it.
Because when $$$x$$$ is too low you can't beat anyone, so there are no possible permutations. Same for high $$$x$$$, when you can beat anyone, so every permutation is good.
Yeah, thank you.
In problem E, i think , lower limit value of x where f(x)!=0 should be max(a[i])-n+1 and not max(a[i])-n and upper limit value of x where f(x)!=n! should be max(a[i])-1 and not max(a[i]). Is it so??
Yeah, maybe it's just for convenience.
Any advice for implementing with E2 binary search?
Anyone please help me why i am getting wrong answer on test case 9 for problem E1. Thanks in advance. https://mirror.codeforces.com/contest/1371/submission/85904339
Ohk , I got my mistake
Please tell what was it?
Why i get wrong answer on test 3 ? https://mirror.codeforces.com/contest/1371/submission/85927710
WOW, I'm stunned when reading through the author's code for problem F.
Compare to my code, It's too complicated
Here is my submission: 86278384
It's beatiful!
cảm ơn em :)
Dạ vâng a :))
There's something wrong with C's tutorial... $$$ m < min(a, b) $$$ should be $$$ m \leq min(a, b) $$$
``
https://mirror.codeforces.com/contest/1371/submission/161919436 why my code is failing for test case 9, pls anyone help!!! my approach is that for each start value from 0 to max_element of array I find out the permutations by doing (x)*(y-1)*(z-2).....*(q-(n-1)) where x : no. of elements less than than first element in array, and same goes for others.
in problem C instead of m < min(a, b) we must write m <= min(a, b) for example 2 2 1 2 with your solve answer will no, but real answer is yes