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

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

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
  • Проголосовать: не нравится

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

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

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

Clashes with TCO22 Round 1A :(

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

such subtasks, so IOI

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

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

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

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

Any ideas on how to solve MODCIRC ?

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

    Shortest path from

    Unable to parse markup [type=CF_MATHJAX]

    to

    Unable to parse markup [type=CF_MATHJAX]

    where the cost of the edge from

    Unable to parse markup [type=CF_MATHJAX]

    to

    Unable to parse markup [type=CF_MATHJAX]

    is

    Unable to parse markup [type=CF_MATHJAX]

    — basically how much you lose from the sum of all $$$a$$$ when you put

    Unable to parse markup [type=CF_MATHJAX]

    after $$$a_i$$$. Since the cost is 0 when

    Unable to parse markup [type=CF_MATHJAX]

    it can be done in $$$O(n^2)$$$.
  • »
    »
    4 года назад, скрыть # ^ |
    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])$$$

»
4 года назад, скрыть # |
 
Проголосовать: нравится +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!

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

Can anyone provide some hints for CONSTMEX? Thanks.

  • »
    »
    4 года назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +8 Проголосовать: не нравится
    Hint
    My Solution
    Code
  • »
    »
    4 года назад, скрыть # ^ |
     
    Проголосовать: нравится 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 $$$ \gt $$$ $$$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)$$$.

    • »
      »
      »
      4 года назад, скрыть # ^ |
      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] \gt suf[j]$$$, $$$a[i] \gt pref[j]$$$, $$$a[j] \gt pref[i]$$$, $$$a[j] \gt suf[i]$$$. It is also equivalent to check weather $$$a[i] \gt max(suf[j],pref[j])$$$ and $$$a[j] \gt 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 \lt 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) \lt c_i.first$$$. This is easily done using a fenwick tree in $$$O(NlogN)$$$ since it is guaranteed that $$$c_i.second \lt 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.

      • »
        »
        »
        »
        4 года назад, скрыть # ^ |
        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$$$).

  • »
    »
    4 года назад, скрыть # ^ |
    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