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

23677번 - Equal Adjacent Elements 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 512 MB107787.500%

문제

Hello sir, I am very interested in coding.. But I am not able to get the solution to a problem. Can you help me??

An array of integers is bad if it contains a pair of equal adjacent elements. An array is good if it is not bad.

You are given a good array. How many ways are there to remove its elements one by one, concatenating the left and right part after each removal, such that at no point the array is bad? Two ways are different if there is a step on which indices of removed elements differ.

For example, after the removal of 1ドル$ from a good array $[2, 1, 2]$ it becomes a bad array $[2, 2]$ and after the removal of 5ドル$ from a good array $[1, 2, 3, 4, 5, 6]$ it becomes $[1, 2, 3, 4, 6]$ and stays good.

Output the answer congruent to the real one modulo 998244353. Formally, if the real answer is $y$ and your answer is $x,ドル it will be considered correct if $-2^{63} \leq x < 2^{63}$ and $x-y$ is divisible by 998244353.

입력

The first line contains a single integer $n$ (1ドル \leq n \leq 500$), the number of elements in the array.

The second line contains $n$ integers $a_i$ (1ドル \leq a_i \leq n$), elements of the array.

출력

Output a single integer --- the answer to the problem modulo 998244353.

제한

예제 입력 1

3
1 2 3

예제 출력 1

6

예제 입력 2

4
1 2 1 2

예제 출력 2

8

예제 입력 3

12
1 2 3 1 2 3 1 2 3 1 2 3

예제 출력 3

25660800

예제 입력 4

1
1

예제 출력 4

-998244352

예제 입력 5

2
1 2

예제 출력 5

998244355

노트

In the first example all elements are distinct, so it's impossible to get a bad array at some point. That's why there are 3ドル! = 6$ ways to remove all the elements.

In the fourth example the real answer is 1ドル$ because there is only one way to remove the only element. The given answer $-998244352$ is congruent to 1ドル$ modulo 998244353, so it is correct too.

In the fifth example the real answer is 2ドル$.

Sorry for my bad English.

출처

Contest > Open Cup > 2018/2019 Season > Stage 13: Grand Prix of Bytedance E번

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

출처

대학교 대회

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

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