Note unusual time duration!
We invite you to participate in CodeChef’s April Lunchtime, this Saturday, 16th April, rated for all.
Time: 8:00 PM — 10:30 PM IST
Joining me on the problem setting panel are:
Setters: Prajwal prajwal7868 Agarwal, Manuj DarkSparkle Nanthan, Nishank IceKnight1093 Suresh, Archit StArChAn Manas, Utkarsh Utkarsh.25dec Gupta, Kanhaiya notsoloud1 Mohan, Anton antontrygubO_o Trygub, Omkar Tripathi
Tester: Harris gamegame Leung
Head Admin: Alex Um_nik Danilyuk
Statement Verifier: Nishank IceKnight1093 Suresh
Contest Admin: Yahor 244mhq Dubovik
Editorialist: Đặng Đoàn Kuroni Đức Trung
Also, announcing Scholarship for CodeChef Certification in Data Structure & Algorithms — More than 100 Indian participants in Divisions 1, 2, and 3 will win scholarships for the CodeChef Certification exam (discounted prices). Scholarship criteria can be found in the respective contest pages.
The video editorials of the problems will be available on our YouTube channel as soon as the contest ends. Subscribe to get notifications about our new editorials.
Also, if you have some original and engaging problem ideas, and you’re interested in them being used in CodeChef's contests, you can share them here.
Hope to see you participating. Good Luck!
Auto comment: topic has been updated by 244mhq (previous revision, new revision, compare).
Clashes with TCO22 Round 1A :(
But you don't need to participate in TCO Round 1A, you already have advanced to TCO Round 4.
such subtasks, so IOI
I was just wondering if this was the right contest.
can someone tell me why this is failing in just two test cases? TIA question- Secret Machine Mania submission
Try this test case
5400 3
. Answer is 5.Were editorials for these three problems released 46 mins before the contest end? I mean they could've been easily accessed by anyone from the edit history if that is the case
https://i.ibb.co/DttYsWp/ddd.png
Any ideas on how to solve MODCIRC ?
Shortest path from $$$a_{max}$$$ to $$$a_{min}$$$ where the cost of the edge from $$$a_i$$$ to $$$a_j$$$ is $$$(a_i - a_i\% a_j)$$$ — basically how much you lose from the sum of all $$$a$$$ when you put $$$a_j$$$ after $$$a_i$$$. Since the cost is 0 when $$$a_i<a_j$$$ it can be done in $$$O(n^2)$$$.
Um... any shortest path with non-negative weights can be done in $$$O(n^2)$$$, it's called Dijkstra.
:D
What I meant is that with proper relaxing you can go over $$$a_i$$$ in fixed order largest to smallest, but I wanted to skip some details, so instead my last sentence is just stupid.
Yeah, and author's original solution was DP, but I feel like just writing standard Dijkstra is simpler than figuring out the relaxation. Maybe not.
What are $$$a_{max}$$$ and $$$a_{min}$$$? Also, how are we ensuring that the minimum path will contain all the vertices?
Maximum and minimum elements. We don't need it to contain all elements, all the other elements can be inserted between $$$a_{min}$$$ and $$$a_{max}$$$ in ascending order without "losing" anything from their sum.
Thanks alot! Really elegant.
If you think about it the smallest integer's value won't decrease and it will always decrease another integer so if you choose that integer the problem returns to be the same.
What you can do is choose a chain of elements in decreasing values such that it starts at the smallest integer and ends at the biggest one and sum $$$A_i \space mod \space A_{i-1}$$$ and sum the rest of integers normally you can get such value using $$$dp[index][prv]$$$ where $$$dp[index][prv] = max(dp[index+1][prv] + a[index], dp[index+1][index] + a[index] \space mod \space a[prv])$$$
I've just read the editorial for ODDSPLIT. I "solved" it by printing bad permutations, finding that they can be split into some cases, and guessing the sequences of their counts. It might be a bit unfortunate that the problem becomes much easier with such guesses (or perhaps fortunate to see some ACs because of that?:)). Anyway I think this problem is beautiful and the editorial is really understandable. Thanks!
Thanks a lot, glad you liked it :)
Can anyone provide some hints for CONSTMEX? Thanks.
Start from 0, then go to 1, ... and observe/prove if there exists some relation between those elements.
Let's assume that you covered the smallest subarray (or range l to r) which has mex = cur. Now if cur-1 lies within (l,r), i.e. cur-1 is not on the boundary and lies inside the range (l,r), then all the elements greater than cur-1 within that range will form a valid pair with cur-1, it will not affect any of the subarray's mex because we have considered the smallest interval (or subarray) with a given mex.
The furthest I got to is that if we have a valid pair ($$$L$$$, $$$R$$$), then both $$$P[L]$$$ and $$$P[R]$$$ should be $$$>$$$ $$$max(MEX(P[0:R-1]), MEX(P[L+1:N-1]))$$$. But I could not get a solution to implement this idea better than $$$O(N^2)$$$.
That's my solution more or less.
Notice that a pair is good if and only if it does not make changes in any prefix/suffix. Let $$$pref_i$$$ be the mex of the $$$i$$$-th prefix ( 1...i ) and $$$suf_i$$$ be the mex of the $$$i$$$-th suffix ( i...n ) and $$$a$$$ be the given array. Thus , for a pair $$$i$$$,$$$j$$$ , we will increment the answer if and only if $$$i$$$ is not the mex in any preffix/suffix and $$$j$$$ is not the mex in any preffix/suffix , and this must hold after swapping the values and before swapping the values. Suppose you keep an array in which we have the values that are not mex in any preffix/suffix. Now, to check weather a pair is good , it is enough to check $$$a[i] > suf[j]$$$, $$$a[i] > pref[j]$$$, $$$a[j] > pref[i]$$$, $$$a[j] > suf[i]$$$. It is also equivalent to check weather $$$a[i] > max(suf[j],pref[j])$$$ and $$$a[j] > max(pref[i],suf[i])$$$. Let's keep some array of pairs $$$c$$$ where $$$c_i$$$ = {$$$a_i, max(pref_i,suf_i)$$$}. Without loss of generality we can assume that $$$a_i < a_j$$$. Thus , sort array $$$c$$$ and now we are left with a problem in which we are given some pairs and we should count the number of $$$(i,j)$$$ such that $$$max(c_i.second,c_j.second) < c_i.first$$$. This is easily done using a fenwick tree in $$$O(NlogN)$$$ since it is guaranteed that $$$c_i.second < c_i.first$$$ by the fact that it should not be a mex in the preffix or a suffix (It's just like counting inversions)
You can check my code here
Updated : by it should not be the mex in a preffix/suffix I actually mean it should not contribute to the mex : i.e. after replacing the value with INT_MAX, the mex should not change.
Thanks a lot!
So I was stuck because I needed to associate each $$$L$$$ with each $$$pref_R$$$ which is $$$O(N^2)$$$.
Your observation reduces this to associate each $$$i$$$ with just $$$max(pref_i, suf_i)$$$. When $$$L$$$ and $$$R$$$ are considered, although $$$pref_L$$$ and $$$suf_R$$$ are unnecessarily considered, they won't change the result as $$$pref_L$$$ is inside $$$pref_R$$$ ($$$pref_R\ge pref_L$$$) and $$$suf_R$$$ is inside $$$suf_L$$$ ($$$suf_L\ge suf_R$$$).
x
, 0 bey
, 2 bez
and assumex < y
. And I am trying to swap positions of 2 with something.z < x
and you try to swap it with some indexi
wherei > x
, then some subarray containing[x, y]
will change their MEX from 2 to 3. But ifi < x
, then the subarray[i..y]
changes its MEX from 2 to 3. So you essentially can't swap it with anything.x < z < y
andz > y
.Based on above observations, solution would turn out to be: - Maintain a range
[l, r]
which indicates that elements between them can be swapped without disturbing the MEX of any subarray. You start withl = y and r = y
and eventually expand this range for1, 2, 3, ..., n-1
.My code