Codeforces и Polygon могут быть недоступны в период с 6 декабря, 22:00 (МСК) по 7 декабря, 00:00 (МСК) в связи с проведением технических работ. ×

Блог пользователя 244mhq

Автор 244mhq, история, 3 года назад, По-английски

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!

  • Проголосовать: нравится
  • +56
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
3 года назад, # |
  Проголосовать: нравится +16 Проголосовать: не нравится

Clashes with TCO22 Round 1A :(

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +73 Проголосовать: не нравится

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

»
3 года назад, # |
  Проголосовать: нравится +52 Проголосовать: не нравится

such subtasks, so IOI

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
3 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

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 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Any ideas on how to solve MODCIRC ?

  • »
    »
    3 года назад, # ^ |
    Rev. 2   Проголосовать: нравится +21 Проголосовать: не нравится

    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 года назад, # ^ |
        Проголосовать: нравится +63 Проголосовать: не нравится

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

      • »
        »
        »
        »
        3 года назад, # ^ |
          Проголосовать: нравится +8 Проголосовать: не нравится

        :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 года назад, # ^ |
            Проголосовать: нравится +3 Проголосовать: не нравится

          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 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

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

      • »
        »
        »
        »
        3 года назад, # ^ |
          Проголосовать: нравится +3 Проголосовать: не нравится

        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 года назад, # ^ |
    Rev. 2   Проголосовать: нравится +13 Проголосовать: не нравится

    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 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

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 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone provide some hints for CONSTMEX? Thanks.

  • »
    »
    3 года назад, # ^ |
    Rev. 2   Проголосовать: нравится +8 Проголосовать: не нравится
    Hint
    My Solution
    Code
  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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 года назад, # ^ |
      Rev. 2   Проголосовать: нравится +15 Проголосовать: не нравится

      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 года назад, # ^ |
        Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

        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 года назад, # ^ |
    Rev. 5   Проголосовать: нравится 0 Проголосовать: не нравится
    • 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