Skip to main content
Back to problems
Codeforces
Medium
Arrays
Math
Dynamic Programming
Domino

Choose a domino placement rule so that the resulting chain is maximized according to the problem’s scoring condition.

Acceptance 0%
Problem Statement

You are given a sequence of dominoes. Each domino can be oriented or chosen according to the rules of the problem, and the task is to determine the best possible result over the whole sequence.

In particular, the solution requires tracking how the effect of one domino influences the next ones and computing the maximum achievable score/length under the allowed transitions. A correct approach usually involves carefully modeling the process, then using efficient counting or prefix-based reasoning to avoid recomputing overlapping states.

Input Format

  • The first line contains the relevant size parameter(s).
  • The following line(s) describe the domino sequence or configuration.
  • All values are integers unless stated otherwise.

Output Format

Print the maximum achievable value required by the problem statement.

Constraints

  • The input size is large enough that an O(n2)O(n^2) brute force approach is not expected.
  • Values fit in standard 32-bit signed integers unless otherwise noted.
  • You should derive an efficient solution based on the transition structure of the domino sequence.
Examples
Sample cases returned by the problem API.

Example 1

Input

5
1 2 2 1 3

Output

3

Explanation

This is a small illustrative example showing a chain-based computation. The best result comes from selecting the longest valid progression under the allowed rule.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.