아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Equal Adjacent Elements

시간 제한2초메모리 제한512 MB

요약
인접한 두 원소가 같은 순간이 한 번도 생기지 않도록 좋은 배열에서 원소를 하나씩 제거하는 순서의 가짓수를 998244353으로 나눈 나머지로 구한다.
난이도

보통10점 중 7점

유형
동적 계획법, 조합론, 구간, 구현
정답자
아직 제출이 없습니다

문제

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 11 from a good array \[2,1,2]\[2, 1, 2] it becomes a bad array \[2,2]\[2, 2] and after the removal of 55 from a good array \[1,2,3,4,5,6]\[1, 2, 3, 4, 5, 6] it becomes \[1,2,3,4,6]\[1, 2, 3, 4, 6] and stays good.

Output the answer congruent to the real one modulo 998244353. Formally, if the real answer is yy and your answer is xx, it will be considered correct if −263≤x<263-2^{63} \leq x < 2^{63} and x−yx-y is divisible by 998244353.

입력

The first line contains a single integer nn (1≤n≤5001 \leq n \leq 500), the number of elements in the array.

The second line contains nn integers a_ia\_i (1≤a_i≤n1 \leq a\_i \leq n), elements of the array.

출력

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

힌트

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!=63! = 6 ways to remove all the elements.

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

In the fifth example the real answer is 22.

Sorry for my bad English.

예제5

  1. 예제 1

    입력
    3
    1 2 3
    
    예상 출력
    6
    
  2. 예제 2

    입력
    4
    1 2 1 2
    
    예상 출력
    8
    
  3. 예제 3

    입력
    12
    1 2 3 1 2 3 1 2 3 1 2 3
    
    예상 출력
    25660800
    
  4. 예제 4

    입력
    1
    1
    
    예상 출력
    -998244352
    
  5. 예제 5

    입력
    2
    1 2
    
    예상 출력
    998244355