Predictor | A | B | C | D | E | F | G |
---|---|---|---|---|---|---|---|
Proof_by_QED | 800 | 1000 | 1100 | 1300 | 1600 | 1900 | 2400 |
cry | 800 | 1000 | 1000 | 1200 | 1700 | 2000 | 2400 |
chromate00 | 800 | 1000 | 1000 | 1400 | 1700 | 2000 | 2400 |
DivinePunishment | 800 | 1200 | 1100 | 1200 | 1700 | 2000 | 2300 |
-firefly- | 800 | 1000 | 1000 | 1400 | 1800 | 2000 | 2400 |
Error_Yuan | 800 | 1100 | 1200 | 1600 | 1800 | 2100 | 2400 |
macaquedev | 800 | 1000 | 1500 | 1400 | 1300 | 2000 | 1900 |
Intellegent | 800 | 900 | 1200 | 1400 | 1700 | 2100 | 2400 |
yoru_sacri | 800 | 900 | 1300 | 1100 | 1700 | 2000 | |
efishel | 800 | 800 | 800 | 1300 | 1600 | 1900 | 2100 |
LMeyling | 800 | 800 | 1100 | 1300 | 1500 | 2100 | 2300 |
larush | 800 | 1000 | 1100 | 1200 | 1600 | 2000 | 2400 |
Dominater069 | 800 | 800 | 900 | 1200 | 1500 | 1900 | 2100 |
A | B | C | D | E | F | G | |
---|---|---|---|---|---|---|---|
Average | 800 | 961.5 | 1100 | 1307.7 | 1630.8 | 2000 | 2291.7 |
2060A - Fibonacciness
Problem Credits: Proof_by_QED
Analysis: larush
We can notice that the possible values of $$$a_3$$$ ranges from $$$-99$$$ to $$$200$$$. Thus, we can iterate over all values of $$$a_3$$$ from $$$-99$$$ to $$$200$$$, and for each value, compute the Fibonacciness of the sequence. The maximal of all these values gives the solution to the problem.
Time Complexity : $$$O(3*a_{max})$$$
$$$a_3$$$ can be represented as either of the following:
$$$a_3 = a_1 + a_2$$$, or
$$$a_3 = a_4 - a_2$$$, or
$$$a_3 = a_5 - a_4$$$.
These are at most 3 possible values. Notice that any value of $$$a_3$$$ which increases the Fibonacciness must belong to one of the above values (Think why!). So, in order to increase the Fibonacciness of the sequence, we should choose the most frequent of the above values. Then, in the end, we can calculate the Fibonacciness of the sequence after choosing the best value for $$$a_3$$$.
Time Complexity : $$$O(1)$$$
2060B - Farmer John's Card Game
Problem Credits: Lilypad
Analysis: larush
Assume the cows are initially ordered correctly. A solution exists if the first cow can place $$$0$$$, the second cow can place $$$1$$$, and so on, continuing with the first cow placing $$$n$$$, the second cow placing $$$n+1$$$, and so forth. Observing the pattern, the first cow must be able to place $$${0, n, 2n, \dots}$$$, the second $$${1, n+1, 2n+1, \dots}$$$, and in general, the $$$i$$$-th cow (where $$$i \in [0, n-1]$$$) must be able to place $$${i, n+i, 2n+i, \dots}$$$.
For each cow, sorting their cards reveals whether they satisfy this condition: the difference between adjacent cards in the sorted sequence must be $$$n$$$. If any cow's cards do not meet this criterion, the solution does not exist, and we output $$$-1$$$.
If the cows are not ordered correctly, we need to rearrange them. To construct the solution, find the index of the cow holding card $$$i$$$ for each $$$i \in [0, n-1]$$$. Since the cards of each cow are sorted, denote $$$\texttt{min_card}$$$ as the smallest card a cow holds. Using an array $$$p$$$, iterate over each cow $$$c$$$ from $$$0$$$ to $$$n-1$$$ and set $$$p_\texttt{min_card} = c$$$. Finally, iterate $$$i$$$ from $$$0$$$ to $$$n-1$$$ and output $$$p_i$$$.
Time Complexity : $$$O(nmlog(m))$$$. Note that sorting is not necessary, and a solution with complexity up to $$$O((nm)^2)$$$ will still pass.
2060C - Game of Mathletes
Problem Credits: LMeyling
Analysis: macaquedev
Note that Bob has all the power in this game, because the order in which Alice picks numbers is irrelevant, since Bob can always pick the optimal number to give himself a point. Therefore, we can just ignore Alice and play the game from Bob's perspective.
From this point on, a "paired" number is any number $$$a$$$ on the blackboard such that there exists a $$$b$$$ on the blackboard such that $$$a+b=k$$$.
Bob's strategy is as follows:
if Alice picks a paired number, Bob should pick the other number in the pair.
if Alice picks an unpaired number, Bob can pick any other unpaired number, it doesn't matter which.
This always works because the number of "unpaired numbers" is always even, since $$$n$$$ is even and the number of "paired numbers" will always be even. Therefore, for every unpaired number Alice picks, Bob will always have an unpaired number to respond with.
Therefore, the final score is just the number of pairs in the input. To count them, use a map of counts $$$c$$$ such that $$$c_x$$$ is the number of occurrences of $$$x$$$ on the whiteboard. Then, for each number from $$$1$$$ to $$$\lfloor \frac{k}{2} \rfloor$$$, take the minimum of $$$c_x$$$ and $$$c_{k-x}$$$, and add that to the total. Remember the edge case where $$$k$$$ is even and $$$x = \frac{k}{2}$$$. The number of pairs here is just $$$\lfloor \frac{c_x}{2} \rfloor$$$.
2060D - Subtract Min Sort
Problem Credits: Proof_by_QED
Analysis: Proof_by_QED
For clarity, let's denote $$$op_i$$$ as an operation performed on $$$a_i$$$ and $$$a_{i+1}$$$.
Claim: if it is possible, then the sequence of operations $$$op_1,op_2,\ldots,op_{n-1}$$$ will sort the array.
Proof: Let $$$b$$$ be any sequence of operations that will sort the array. Let's transform the sequence $$$b$$$ such that it becomes $$$[op_1,op_2,\ldots,op_{n-1}]$$$.
First, let's note that an $$$op_i$$$ does nothing if $$$a_i=0$$$ or $$$a_{i+1}=0$$$. Additionally, after $$$op_i$$$, at least one of $$${a_i,a_{i+1}}$$$ will become zero. Thus, we can remove all duplicates in $$$b$$$ without altering the result.
Now, let $$$x$$$ be the largest number such that $$$op_x$$$ is in $$$b$$$. Since at least one of $$$a_x,a_{x+1}$$$ will be zero, operations must be performed such that each of $$$a_1,a_2,\ldots,a_{x-1}$$$ are zero. Let $$$S$$$ be the set of indices with $$$i<x$$$ such that $$$op_i$$$ is not in $$$b$$$. Note that we can simply append each operation in $$$S$$$ at the end of $$$b$$$ without altering the result, since all elements before $$$a_x$$$ are already zero.
Our sequence of operations now contain a permutation of $$$op_1,op_2,\ldots,op_x$$$, and we have ensured that all of $$$a_1,a_2,\ldots,a_x=0$$$. Since the sequence is now sorted, we can in fact continue performing $$$op_{x+1},op_{x+2},\ldots,op_{n-1}$$$ in this order. Notice that this sequence of operations will keep our array sorted, as $$$op_y$$$ will make $$$a_y=0$$$ (since $$$a_y<a{y+1}$$$).
Let's show that we can rearrange our operations such that $$$1$$$ comes first. There are two cases: either $$$op_1$$$ comes before $$$op_2$$$, or $$$op_2$$$ comes before $$$op_1$$$. In the first case, notice that no operation done before $$$op_1$$$ will impact either the value of $$$a_1$$$ or $$$a_2$$$, so rearranging such that $$$op_1$$$ comes first does not impact the final results. In the second case, notice that after $$$op_2$$$ is done, we must have $$$a_1=a_2$$$, as otherwise $$$op_1$$$ will not simultaneously make $$$a_1=a_2=0$$$. This implies that right before $$$op_2$$$ is performed, we must have $$$a_1+a_3=a_2$$$. Then, rearranging the operations such that $$$op_1$$$ comes first will not impact the final result.
Using the same line of reasoning, we can make $$$op_2$$$ the second operation, then $$$op_3$$$, and so on. To solve the problem, we can simply simulate the operations in this order, and then check if the array is sorted at the end.
Time Complexity : $$$O(n)$$$
2060E - Graph Composition
Problem Credits: LMeyling
Analysis: DivinePunishment
Let's solve the problem for each operation.
First, consider the operation that removes an edge from $$$ F $$$. Divide $$$ G $$$ into its connected components and assign each vertex a component index. Then, for each edge in $$$ F $$$, if it connects vertices with different component indices, remove it and increment the operation count.
This guarantees no path between $$$ x $$$ and $$$ y $$$ in $$$ F $$$ if there is none in $$$ G $$$. Next, to ensure a path exists between $$$ x $$$ and $$$ y $$$ in $$$ F $$$ if there is one in $$$ G $$$, we divide $$$ F $$$ into connected components. After removing excess edges, each component of $$$ F $$$ only contains vertices of the same component index. The number of operations needed now is the difference between the number of connected components in $$$ F $$$ and $$$ G $$$.
All operations can be efficiently performed using DFS or DSU.
2060F - Multiplicative Arrays
Problem Credits: Proof_by_QED, cry
Analysis: -firefly-
When $$$n$$$ is large, many of the array's elements will be $$$1$$$.
The number of non-$$$1$$$ elements can't be so large.
Try to precompute all arrays without $$$1$$$ and then use combinatorics.
The naive solution is to define $$$f_k(n)$$$ as the number of arrays containing $$$n$$$ elements with a product of $$$k$$$. We could then try to compute this by considering the last element of the array among the divisors of $$$k$$$, giving us:
with $$$f_k(1)=1$$$.
The answers would then be $$$\sum_{i=1}^{n}f_1(i),\sum_{i=1}^{n}f_2(i),\dots,\sum_{i=1}^{n}f_k(i)$$$. However, this leads to an $$$O(nk\log k)$$$ solution, which exceeds our time constraints. We need to optimize this approach.
We can prove that there are at most $$$16$$$ non-$$$1$$$ elements in our arrays. This is because:
- The prime factorization of $$$k=p_1p_2\cdots p_t$$$ divides $$$k$$$ into the most non-$$$1$$$ elements.
- With $$$17$$$ non-$$$1$$$ elements, the smallest possible value would be $$$k=2^{17}=131072>10^5$$$.
Based on this observation, we can define our dynamic programming state as:
- Let $$$dp[i][j]$$$ represent the number of arrays with product $$$i$$$ containing only $$$j$$$ non-$$$1$$$ elements.
- The recurrence relation becomes: $$$dp[i][j]=\sum_{p|i,p>1}dp[p][j-1]$$$.
- Base case: $$$dp[i][1]=1$$$ for $$$i>1$$$.
This computation has a time complexity of $$$O(k\log^2k)$$$, as we perform $$$\sum_{j=1}^{k}d(j)=O(k\log{k})$$$ additions for each $$$i$$$.
To calculate $$$f_k(n)$$$, we:
- Enumerate the number of non-$$$1$$$ elements from $$$1$$$ to $$$16$$$.
- For $$$j$$$ non-$$$1$$$ elements in the array:
- We have $$$n-j$$$ elements that are $$$1$$$.
- We need to choose $$$j$$$ positions for non-$$$1$$$ elements.
- Fill these positions with $$$dp[k][j]$$$ possible sequences.
This gives us:
Therefore:
Note that $$$\sum_{i=1}^{n}\binom{i}{j} = \binom{n+1}{j+1}$$$ is given by the Hockey Stick Identity.
Each answer can be calculated in $$$O(\log^2k)$$$ time, giving an overall time complexity of $$$O(k\log^2k)$$$.
Let's revisit the naive approach and define $$$S_k(n)=\sum_{i=1}^{n}f_{k}(n)$$$ as our answers. We can observe:
Accumulating Formula $$$(1)$$$ yields:
By induction, we can prove that both $$$f_{k}(n)$$$ and $$$S_k(n)$$$ are polynomials. Let's denote:
- Degree of $$$f_k(n)$$$ as $$$p(k)$$$.
- Degree of $$$S_k(n)$$$ as $$$q(k)$$$.
From the definition of $$$S_k(n)$$$, we have $$$q(k)=p(k)+1$$$. Formula $$$(2)$$$ gives us:
with $$$p(1)=0$$$. By induction, we can show that $$$p(k)$$$ equals the number of primes in $$$k$$$'s prime factorization. Therefore, $$$p(k)\le16$$$ and $$$q(k)\le17$$$.
Since $$$q(k)$$$ doesn't exceed $$$17$$$, we can:
- Precompute $$$S_k(1),S_k(2),S_k(3),\dots,S_k(18)$$$.
- Use Lagrange Interpolation to compute any $$$S_k(n)$$$.
This also yields an $$$O(k\log^2k)$$$ time complexity.
2060G - Bugged Sort
Problem Credits: chromate00
Analysis: macaquedev
Consider $$$(a_i, b_i)$$$ as the $$$i$$$-th pair. Can two elements ever become unpaired?
No. Every operation keeps the pairs intact. The best way to think about the operation is like this:
Swap the pairs at index $$$i$$$ and index $$$j$$$.
Flip each pair (swap $$$a_i$$$ with $$$b_i$$$, and $$$a_j$$$ with $$$b_j$$$).
The operations allow us to swap two pairs, but it also results in both of them getting flipped. Is there any way to swap two pairs without flipping anything?
It turns out there is, and there always is, because $$$n \geq 3$$$. To swap pairs $$$i$$$ and $$$j$$$, follow this procedure:
Pick any index $$$k$$$, where $$$k \ne i$$$ and $$$k \ne j$$$.
Do the operation on $$$i$$$ and $$$k$$$.
Do the operation on $$$j$$$ and $$$k$$$.
Finally, do the operation on $$$i$$$ and $$$k$$$ again. This results in the pair at index $$$k$$$ being unchanged, and the pairs at $$$i$$$ and $$$j$$$ simply being swapped.
Can you flip two pairs without swapping them?
Yes. Just perform the operation on pairs $$$i$$$ and $$$j$$$, and then follow the procedure from Hint 2, and you are effectively swapping, then "swapping and flipping", therefore the final result is simply a flip of two pairs.
Can you flip one pair on its own?
No, this is not possible due to the parity invariant. The operation involves performing two swaps at the same time, which means that it is impossible to end up in a situation where the number of swaps is odd.
Read the hints first.
Key observation:
In the final solution, the pairs must be sorted in increasing order of $$$\min(a_i, b_i)$$$. We prove this by contradiction. Suppose there exists a pair $$$(a_i, b_i)$$$, where $$$a_i < b_i$$$ and $$$a_i$$$ is smaller than the minimum element in the previous pair. In this case, it becomes impossible to place this pair after the previous one, as $$$a_i$$$ would always be smaller than the preceding element, regardless of orientation.
Since all $$$a_i$$$ and $$$b_i$$$ are distinct, there is exactly one valid final ordering of the pairs. Moreover, this ordering is always reachable because we previously proved that any two pairs can be swapped without flipping their elements. Since swapping any two items in an array an arbitrary number of times allows for sorting by definition, we can sort the pairs in this order. Thus, the solution is to initially sort the pairs based on $$$\min(a_i, b_i)$$$.
Solution:
The problem simplifies to determining whether flipping pairs allows sorting. We can solve this using dynamic programming (DP), defined as follows:
$$$dp[1][i] = 1$$$ if it's possible to sort up and including pair $$$i$$$ using an even number of flips, where pair $$$i$$$ is not flipped.
$$$dp[2][i] = 1$$$ if it's possible to sort up and including pair $$$i$$$ using an even number of flips, where pair $$$i$$$ is flipped.
$$$dp[3][i] = 1$$$ if it's possible to sort up and including pair $$$i$$$ using an odd number of flips, where pair $$$i$$$ is not flipped.
$$$dp[4][i] = 1$$$ if it's possible to sort up and including pair $$$i$$$ using an odd number of flips, where pair $$$i$$$ is flipped.
The base cases are as follows:
$$$dp[1][1] = 1$$$, because this represents the state where the first pair is not flipped, resulting in zero flips (which is even)
$$$dp[4][1] = 1$$$, because this represents the state where the first pair is flipped, resulting in one flip (which is odd).
There are eight possible transitions, as you can reach each of the four states from two previous states: you either choose to flip the current element or you don't.
The final answer is $$$dp[1][n]$$$ $$$\texttt{OR}$$$ $$$dp[2][n]$$$, because by Hints 3 and 4, we can only reach states where an even number of pairs are flipped from the starting position.
C took me incredibly long. I was completely overcomplicating it thinking that we needed to subtract from the answer when there was an odd number of non-pair numbers.
hahaha, I did the same. I didn't realize the fact that non pair numbers can never be odd up until the contest ended, so silly.
hahahaha me too bro
same
Same, I didn't read that n is even only :(
It was a nice contest! I got stuck on problem E, but I'll learn from it.
today was the 1st time ever i reached problem E :), all the best to u!
I solved 4 but took a shit long of time.Damn That A ,A problem statement can be better
At first reading your comment, I thought you actually had to take a dump during the contest. I almost felt sorry for you.
Why is F so damn hard???
Is it me or the B problem was kind of hard to implement ? It took me a while to solve it. Even the total number of users who solved the problem is less than the problem C.
understanding that statement took me some time ..implementation is easy
As an AKer in 2h29min, I think this is closer to DIV2 ;)
Problem G is very good.
I lost like 1000-2000 rank because of B and D :( and also got too confident on my two different solutions to E and submitted them both. But nevertheless, This was the most problems I ever solved in any contest yet and I am quite happy.
Imo, C was easier than B.
Can anyone explain D?
Got it
contest was really cool...solved A,C but couldn't solve B:(
I solved A, C and D but can't solve B. I don't know what is the logical mistake in my solution.
my approach which might help:
store in the form of int[n][m] sort all vectors find order by taking first el of all check if order is valid, else -1
I created a vector of size n * m, and for each card assigned the number of the person holding it. The problem stated that you have cards starting from 0 to n * m — 1 and each card has to be greater than the last one. So with this array, you already have the sequence:
Cow 1 has cards: 1 4 7
Cow 2 has cards: 5 2 8
Cow 3 has cards: 0 3 6
The vector will be {3, 1, 2, 3, 1, 2, 3, 1, 2}. We have 3 cows, so we only get the sequence from up to index |qty. of cows-1| and check if it is equal the rest of the sequence.
check for edge case n=1
consider total m rounds.
In each round that is total N cows will place a card. so,First create a map of all the numbers (0->n*m-1)-> for each number assign the cow. which cow is holding this particular card. Now iterate from z=0.(this is current card number) total we have to place m rounds .and in each round total n cows has to participate. say in round 1 -> z=0->search which cow has this z=0 number.insert that into a vector. increment z; z=1->search which cow has this z=1 .insert that cow number into a vector. after "n" cows played a permutation will be generated. you have to make sure that this is the only permutation will come at the end of the M rounds.
insert this vector into a set after each round.
at the end check whether the size is 1 or not you can refer
https://codeforces.me/contest/2060/submission/301815602
Did anyone use Faulhaber formula to solve F?
I tried that at first, but then I realised my way of counting was wrong lol
what is the issue in this code of D https://codeforces.me/contest/2060/submission/301878766
Test Case :
1
4
1 3 5 2
Expected Ans : NO
Your Code Output : YES
I did the same at first , you can see my solution and find that we almost coded the same thing , except we both ignored the fact to change a[i-1] , we only focused on changing a[i] , you might ask how does that affect out solution.... Well , for the given test case : n = 8 a = [4 5 4 5 4 5 4 5] try printing your answer , it gives: [4 1 4 1 4 1 4 5] which is non decreasing , but still the answer is YES and that's a fluke.... so what is our next approach? Well luckily for us we dont need to change a lot in this code , just make sure to understand the fact that , we won't change the values only when a[i] > a[i + 1] , we might need to do it otherwise as well , its kinda hard to explain the intution , until i come up with a proper proof but a rough proof might look like : let's take the above array that i used as an example , there your code didn't use the operation on 2nd index(0 based) and hence in the answer array we get a 4 , instead if we had applied the operation then the answer array would've looked like [0 0 0 0 0 0 0 4] so just apply this operation on all the indices , and check in the end if it is sorted or no , lmk if you have any doubt , here's my submission : here
good contest , bad contest
My brute force is failed for C. Its was basic level question
The testcases for E couldve been better. I just thought we have to make both the graphs same but i guess thats what makes me a newbie
i guess also thought the same after WA i thought another solution lol
thank for contest
man i dont know why my c is wrong .
Maybe, you are erasing from the vector ,this will change the vector,so in future issues mayrise with the upperbound and lowerbound later.these upper bound and lowerbound may change and they may not the ones which you think they'll be..Try out a test case and try printing all the upperbound's and lowerbound's and see..
It fails on this testcase: 1 2 4 2 3
why 301896773 gives TLE when submitted in C++20 but accepted when submitted in C++17
I'm quite new to graph theory problems, so please pardon any ignorance. However, for the life of me, I cannot understand why in problem E you cannot just count the number of pairs of (u, v) that are in G and not F, and the pairs in F but not G?
consider the testcase
1
4 2 2
1 3
2 3
1 2
1 3
the answer is zero
but according to you answer will be 2
If (u, v) does exist in G, but not in F, it doesn't mean that you can not reach v from u (u -> w -> v)
Aha! I guess I assumed that the problem only wanted one edge between (u, v).
Consider F = 1-2-3-4 and G = 1-4-2-3
Can someone explain how for E on the second test of test 2 the # of operations needed is only 2? I'm getting 33.
oh as long as there is a path between them it works didn't realize that
F was awesome
Nice contest. D was pretty easy, though.
didn't you get it hacked ??
Nope, not yet at least. Might get hacked since I didn't really think much on it aside for my initial doubts about my approach being too simple to work.
Jeez!! I got stuck on problem E. Now reading the tutorial I noticed that I had the idea but still have lots of problems on the implementation looool. Btw, interesting contest, good problems. Wanna upsolve rn!!!!
301778309 Can someone point out the error in this for B?
Any good resources to learn combinatorics?
Self review no one asked for:
so mad that i sold around 50 penalty points because of the misread on a...
i lost a little time on b because of interesting construction
rushed on c, my mind was too disorganized
c-d turnaround was lowkey clean, i hit an instant mindsolve
e i sent two wa because i thought we needed to simply match the edge list, rather than the path. test case 1 seemed to support this. i sent another wa submission because i thought it was overflow
f and g were beyond me
Quite same. Got stuck on A and thought I was screwed. Than tried D and bam! solved it in first go. C was also a smooth sailing, but got stuck at B again. I really don't know what to feel as A and B gave me more trouble than my whole college exams combined.
My man, at least you realize it in time.
When I was realized I read the problem E wrong, the contest is already over.
It only took me ~ 30 min of implementation so if I could realize I read the problem wrong, I can comeback easily (theoretically)...
Ready going back to pupils and wait for Div 4.
can I know the extension that you are using to predict the rating changes
Why was d at d?
Because we hoped that some people will prove the result instead of resorting to guessing that the obvious strategy works, and the proof is actually not so simple.
Hey can you tell me whethe my proof was correct?
I started from the first index of array and started taking the mid of first two elements. Than I subtracted it from both. Than we will reduce one element to 0 and the next to whatever was left after subtracting. By the way this was done only when first element was smaller than second as otherwise if this operation is performed there is no way that array can be non decreasing as zero is the minimum element obtainaible and everytime we pair an element with 0 the min of them both will be zero. So if we get something like 1 0 than it's likely impossible but if we have smooth sailing till last index than you are good to go.
Does it seem satisfactory or you have a better proof? I'd love to hear your take.
This doesn't tell me why it is optimal to decrease on the first element first. Perhaps it is better to do them in a different order. My proof is in editorial
There is an easier solution for G without dp and more straightforward to prove(?). Imagine $$$a$$$ and $$$b$$$ stacked on top of each other, draw an arrow pointing downwards from $$$a_i$$$ to $$$b_i$$$ if $$$a_i > b_i$$$ otherwise draw an upwards arrow from $$$b_i$$$ to $$$a_i$$$. Now doing an operation on $$$(i,j)$$$ is equivalent to swapping the pairs $$$(a_i,b_i),(a_j,b_j)$$$ then flipping their arrows.
Following from the editorial, the order of the pairs in the final sorted configuration is fixed and we can freely reorder the pairs. The question left is whether we can orient the arrows correctly?
Assume we already fixed the final direction of each arrow in the final state, the number of up arrows in the final and initial state has to have the same parity (parity of up arrows is invariant under swapping). So we now ask what possible parities of up arrows can the final state have?
First sort the pairs by $$$\min(a_i,b_i)$$$. For each $$$i$$$, if $$$\max(a_i,b_i) > min(a_{i+1},b_{i+1})$$$ then their arrows must share the same direction, otherwise they can be different or the same. Now we split the pairs into consecutive segments where each all arrows in the same segment must have the same direction. The parity of number of up arrows can be $$$0$$$ or $$$1$$$ iff there exist a segment of odd length because changing the direction of all arrows in an even segment does not change the parity of up arrows. The answer to yes or no reduces to these two conditions:
1) No $$$\max(a_i,b_i) > \min(a_{i+1},b_{i+1})$$$ exist
2)There exist an odd segment or the parity of up arrows in the initial state is even
My solution is similar to yours, but I think you're missing one case.
Even if all the fixed segments are even length, if there exists two consecutive
i
's wheremax(ai,bi)>min(ai+1,bi+1)
is false, then you can flip the first of those twoi
's without changing anything else. This means you can always make the total number of flips even.(Also you still have to check that after ordering the pairs, one of the flips (or arrow directions) is valid — such as in the first example test case where the middle pair can never be valid.)
Yes that condition should be condition 1), I miswrote $$$\min(a_{i+1},b_{i+1})$$$ as $$$\max(a_{i+1},b_{i+1})$$$
In the tutorial of B, it says in general,
the i-th cow (where i∈[0,n−1]) must be able to place i,n+i,2n+i,….
but what if the input is
1
3 3
3 4 5
0 1 2
6 7 8
here there is still a possible permutation but not according to the tutorial ??
No player can play consecutive turns, so suppose player 2 plays 0, player 1 plays 3, and player 3 plays 6, then player 2 can't play any of his cards since they are smaller than 6. (If you think that player 2 can play all his cards, then player 1, then player 3, then you might have misread the question) A player will only get his turn after all other players have played, everyone maintains the same turn order throughout the game
"Farmer John wants the game to be fair, so each cow should only be able to play 1 card per round."
Maybe you read too fast or forgot about this part.
In problem F solution 1, how are we calculating \begin{align*} \binom{n+1}{j+1} \end{align*}
since n is very large?
n is large, but j is small. You can compute in O(j) time.
Oh, got it. Thanks.
$$$\binom{n+1}{j+1} = (n+1)(n)(n-1)\ldots (n-j)/(j+1)!$$$, there are only $$$j+1$$$ terms in the binomial
my downfall was A. I don't know why I was overthinking it so much when it was so obvious. Took me nearly one hour to solve. I really have a lot to learn...
Amazing contest! I was able to solve A, B, C on whiteboard. Hope to see more contests like this!
Is it just me or anyone else feels like there are a bunch of people using AI to solve the problems, given LLM's are basically on Master's level. Some low rank people just straight up solve E. I tried plugging the question into ChatGPT and it instantly gave me a working answer. What is the future of these types of contests?
For D I used a completely different approach, where the logic (at least if you have to prove it!) is simpler: starting from the end, find the allowed interval for the previous element. Then check that the first element fits in the required interval.
Although B is quiet easy there is better way to implement it(or should I say more efficient)(although the logic remains the same) , we could just find the modulo the elements of each row with n if they are all the same , then it is possible else it isn't . Finding the permutation is also easy , we can just create an array and append the remainders (if they are all equal for a row). Now the permutation would be the remainder+1 . The time complexity would be $$$O(n*m)$$$ here (This is what I did during the contest).[I know that this is fairly simple problem , but I thought this would be nice to point out nonetheless]
Damn... I've used DSU implementation from Algorithmica. And it was wrong all from the start. Spent 30 minutes to find a bug in my solution, and the only bug was my trust in this site.
Use Striver's DSU. It is the best in my opinion.
Can anyone explain why my solution of B 301795916 is giving wa.
I solved G without using dynamic programming and I think it's a bit more intuitive (at least for me).
Using the same insights as mentioned in the hints, my solution builds out a possible answer and checks if it has enough degrees of freedom to end up with an even number of flips, or necessarily has an even number of flips.
Say you've placed the first n pairs (as the editorial mentions, this order is fixed by $$$min(a_i, b_i)$$$), then you take the next smallest pair and decide how it should be flipped. There are 4 cases:
"NO"
. This would be like in the first example case where you place $$${1, 6}$$$ first and then have to place $$${2, 4}$$$, but no matter how you flip $$${2, 4}$$$ the number after the array with 6 will no longer be increasing.You don't need to track the whole array, just the chosen state of the previous pair, which you can initialize as $$${-1, -1}$$$ (since the first actual pair can have either orientation).
If at any point you have two in a row which can be either orientation, then you can flip or not flip that fist one to make the total number of swaps even, regardless of how the total turns out. From this point on, you will return
"YES"
as long as you don't find a situation where a pair can't be either orientation.You will also want to track the number of fixed orientations there are in a row. If you end up with a block of fixed orientations which is of an even count, then you can flip the pair just before this block (which is necessarily one that can be either orientation, otherwise it would be part of this block) which would flip the orientation of all the pairs in this block as well, which will have flipped the orientation of an odd number of pairs, meaning the number of total flips will have gone from even to odd or vice versa. This freedom will mean no matter what the parity of the other fixed blocks are, you can make the total number of flips even or odd.
After going through all pairs, if you found either degree of freedom (either two free pairs in a row, or a block of fixed pairs of even count) or the number of flips applied for the array you built is already even, then it's possible.
Why is dp[3][1] = 1 in solution of question G? Shouldn't the dp[4][1] be equal to 1 since we flip the first pair and the total flips is equal to 1?
Editorial author here. Sorry, just a really annoying typo, because I got confused between zero and one-based indexing! It's definitely meant to be dp[4][1].
in c we can count number of pairs using 2 pointers, i did so so maybe update tags
In problem F, why are we only doing (n,j), there can be sequence of repeated factors as well which will reduce the multiple.
i.e. example consider a sequence [2,3,3,4,4,4] and then (n-6) 1's for any n. The multiple should be n!/((n-6)! * 2! * 3!)