Codeforces and Polygon may be unavailable from December 6, 19:00 (UTC) to December 6, 21:00 (UTC) due to technical maintenance. ×

244mhq's blog

By 244mhq, history, 3 years ago, In English

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:

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!

  • Vote: I like it
  • +56
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by 244mhq (previous revision, new revision, compare).

»
3 years ago, # |
  Vote: I like it +16 Vote: I do not like it

Clashes with TCO22 Round 1A :(

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +73 Vote: I do not like it

    But you don't need to participate in TCO Round 1A, you already have advanced to TCO Round 4.

»
3 years ago, # |
  Vote: I like it +52 Vote: I do not like it

such subtasks, so IOI

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +18 Vote: I do not like it

    I was just wondering if this was the right contest.

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

can someone tell me why this is failing in just two test cases? TIA question- Secret Machine Mania submission

»
3 years ago, # |
  Vote: I like it +3 Vote: I do not like it

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

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Any ideas on how to solve MODCIRC ?

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it +21 Vote: I do not like it

    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)$$$.

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it +63 Vote: I do not like it

      Um... any shortest path with non-negative weights can be done in $$$O(n^2)$$$, it's called Dijkstra.

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it +8 Vote: I do not like it

        :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.

        • »
          »
          »
          »
          »
          3 years ago, # ^ |
            Vote: I like it +3 Vote: I do not like it

          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.

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      What are $$$a_{max}$$$ and $$$a_{min}$$$? Also, how are we ensuring that the minimum path will contain all the vertices?

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it +3 Vote: I do not like it

        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.

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it +13 Vote: I do not like it

    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])$$$

»
3 years ago, # |
  Vote: I like it +1 Vote: I do not like it

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!

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone provide some hints for CONSTMEX? Thanks.

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it +8 Vote: I do not like it
    Hint
    My Solution
    Code
  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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)$$$.

    • »
      »
      »
      3 years ago, # ^ |
      Rev. 2   Vote: I like it +15 Vote: I do not like it

      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.

      • »
        »
        »
        »
        3 years ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        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$$$).

  • »
    »
    3 years ago, # ^ |
    Rev. 5   Vote: I like it 0 Vote: I do not like it
    • Position of 0 can't change because then you would be changing the MEX of that subarray (of size 1) to 0 from 1.
    • Position of 1 can't change (similar reasoning, think of subarray containing both 0 & 1)
    • Now, think when you can change the position of 2. Let index of 1 be x, 0 be y, 2 be z and assume x < y. And I am trying to swap positions of 2 with something.
    • If z < x and you try to swap it with some index i where i > x, then some subarray containing [x, y] will change their MEX from 2 to 3. But if i < x, then the subarray [i..y] changes its MEX from 2 to 3. So you essentially can't swap it with anything.
    • Similarly argue for case x < z < y and z > 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 with l = y and r = y and eventually expand this range for 1, 2, 3, ..., n-1.

    My code