Logo
(追記) (追記ここまで)

33127번 - Microwavable Subsequence 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB55433982.979%

문제

You are given an array of $N$ integers: $[A_1, A_2, \dots , A_N ]$.

A subsequence can be derived from an array by removing zero or more elements without changing the order of the remaining elements. For example, $[2, 1, 2],ドル $[3, 3],ドル $[1],ドル and $[3, 2, 1, 3, 2]$ are subsequences of array $[3, 2, 1, 3, 2],ドル while $[1, 2, 3]$ is not a subsequence of array $[3, 2, 1, 3, 2]$.

A subsequence is microwavable if the subsequence consists of at most two distinct values and each element differs from its adjacent elements. For example, $[2, 1, 2],ドル $[3, 2, 3, 2],ドル and $[1]$ are microwavable, while $[3, 3]$ and $[3, 2, 1, 3, 2]$ are not microwavable.

Denote a function $f(x, y)$ as the length of the longest microwavable subsequence of array $A$ such that each element within the subsequence is either $x$ or $y$. Find the sum of $f(x, y)$ for all 1ドル ≤ x < y ≤ M$.

입력

The first line consists of two integers $N$ $M$ (1ドル ≤ N, M ≤ 300,円 000$).

The second line consists of $N$ integers $A_i$ (1ドル ≤ A_i ≤ M$).

출력

Output a single integer representing the sum of $f(x, y)$ for all 1ドル ≤ x < y ≤ M$.

제한

예제 입력 1

5 4
3 2 1 3 2

예제 출력 1

13

The value of $f(1, 2)$ is 3ドル,ドル taken from the subsequence $[2, 1, 2]$ that can be obtained by removing $A_1$ and $A_4$. The value of $f(1, 3)$ is 3ドル,ドル taken from the subsequence $[3, 1, 3]$ that can be obtained by removing $A_2$ and $A_5$. The value of $f(2, 3)$ is 4ドル,ドル taken from the subsequence $[3, 2, 3, 2]$ that can be obtained by removing $A_3$. The value of $f(1, 4),ドル $f(2, 4),ドル and $f(3, 4)$ are all 1ドル$.

예제 입력 2

3 3
1 1 1

예제 출력 2

2

The value of $f(1, 2)$ and $f(1, 3)$ are both 1ドル,ドル while the value of $f(2, 3)$ is 0ドル$.

힌트

출처

ICPC > Regionals > Asia Pacific > Indonesia > Jakarta > The 2024 ICPC Asia Jakarta Regional Contest I번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /