CCO '24 P5 - Heavy Light Decomposition

View as PDF

Submit solution

Points: 20 (partial)
Time limit: 4.0s
Memory limit: 1G

Problem types

In an array containing only positive integers, we say an integer is heavy if it appears more than once in the array, and light otherwise.

An array is good if the integers in the array alternate between light and heavy.

Given an array a1,,aN, count the number of ways to partition it into some number of contiguous subarrays such that each subarray, when considered as an array on its own, is good. As the answer may be large, output it modulo 1000003.

Input Specification

The first line of input contains a single integer, N.

The next line contains N integers a1,,aN (1aiN).

Marks Awarded Bounds on N Additional Constraints
3 marks 2N50000 For each i, ai26.
4 marks 2N5000 No additional constraints.
5 marks 2N500000 If i is odd, then ai=1.
6 marks 2N500000 Any number appears at most twice in the array.
7 marks 2N500000 No additional constraints.

Output Specification

The number of ways to partition the array into good contiguous subarrays, modulo 1000003.

Sample Input 1

Copy
5
1 2 3 2 3

Sample Output 1

Copy
4

Explanation for Sample 1

There are four valid partitions of [1,2,3,2,3]:

  • [1], [2], [3], [2], [3]
  • [1], [2,3,2], [3]
  • [1], [2], [3,2,3]
  • [1,2,3,2], [3]

Sample Input 2

Copy
5
1 2 1 3 1

Sample Output 2

Copy
6

Comments

There are no comments at the moment.