kavascg's blog

By kavascg, history, 7 weeks ago, In English

Suppose we partition the elements of an array b into any number k of non-empty subarrays S1,S2,…,Sk , where k is an arbitrary positive integer. Define the score of b as the maximum value of MEX(S1)+MEX(S2)+…+MEX(Sk) over all possible partitions of b for any integer k n <= 2e5

continous subarrays not for subsequence for [0 0 1 1] ans is 3

how can i calculate score .

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
7 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

I misread the problem

  • »
    »
    7 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    how would u implement it? like how would you make partition i can think of an O(n^2) approach and ans for [ 0 1 2 3 6 5 4 3 2 1 0 0] will be 12

»
7 weeks ago, # |
Rev. 3   Vote: I like it +7 Vote: I do not like it

The solution is:

Make a frequency table, store the frequency of all elements in the array, make a prefix (min) array of that frequency table, the answer is the sum of all elements in the prefix min array.

Code

A nice problem that uses the same idea : 2030E - MEXimize the Score

  • »
    »
    7 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    this would be for subsquence for subarray it would be diff [0 0 1 1 ] will have ans 3

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

This looks like DP where dp[i] is the score of the prefix until i but I didn't solve yet

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
7 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Can you write the problem a bit better? What is the constraint on the numbers in the array?

Where can I try submitting the problem to test?

Few observations (Assuming the array only contains non-negatives):

  1. If any partition doesn't contain 0 then MEX of that partition is 0. So, we need to partition as much as possible with 0s. Because if there are no 0s, then sum of all MEX = 0.

Here's a possible solution based on above observation but I am still thinking on how to prove that this is optimal.

Count 0s in the array. No 0s means ans = 0 (because no matter how many partitions you do, MEX of each partition is 0). That many partition should be optimal. Now, the question comes how to do a partition. We can find the left most 0. Then partition, that much prefix (index 0 of array and index of first 0). Then from first 0 till second 0, there should be some part of array that belongs to first 0 and some part that belongs to second 0. This is where I am stuck..but I think the solution would be in this direction.