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

18261번 - Tree Depth 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB46302775.000%

문제

For the new year, Farmer John decided to give his cows a festive binary search tree (BST)!

To generate the BST, FJ starts with a permutation $a=\{a_1,a_2,\ldots,a_N\}$ of the integers 1ドル\ldots N,ドル where $N\le 300$. He then runs the following pseudocode with arguments 1ドル$ and $N.$

generate(l,r):
 if l > r, return empty subtree;
 x = argmin_{l <= i <= r} a_i; // index of min a_i in {a_l,...,a_r}
 return a BST with x as the root, 
 generate(l,x-1) as the left subtree,
 generate(x+1,r) as the right subtree;

For example, the permutation $\{3,2,5,1,4\}$ generates the following BST:

 4
 / \
 2 5
 / \ 
1 3

Let $d_i(a)$ denote the depth of node $i$ in the tree corresponding to $a,$ meaning the number of nodes on the path from $a_i$ to the root. In the above example, $d_4(a)=1, d_2(a)=d_5(a)=2,$ and $d_1(a)=d_3(a)=3.$

The number of inversions of $a$ is equal to the number of pairs of integers $(i,j)$ such that 1ドル\le i<j\le N$ and $a_i>a_j.$ The cows know that the $a$ that FJ will use to generate the BST has exactly $K$ inversions $(0\le K\le \frac{N(N-1)}{2})$. Over all $a$ satisfying this condition, compute the remainder when $\sum_ad_i(a)$ is divided by $M$ for each 1ドル\le i\le N.$

입력

The only line of input consists of three space-separated integers $N, K,$ and $M,ドル followed by a new line. $M$ will be a prime number in the range $[10^8,10^9+9].$

출력

Print $N$ space-separated integers denoting $\sum_ad_i(a)\pmod{M}$ for each 1ドル\le i\le N.$

제한

예제 입력 1

3 0 192603497

예제 출력 1

1 2 3

Here, the only permutation is $a=\{1,2,3\}.$

예제 입력 2

3 1 144408983

예제 출력 2

3 4 4

Here, the two permutations are $a=\{1,3,2\}$ and $a=\{2,1,3\}.$

힌트

출처

Olympiad > USA Computing Olympiad > 2019-2020 Season > USACO 2019 December Contest > Platinum 3번

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

출처

대학교 대회

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

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