RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0398 파일 입출력

Tree Depth

Ruby V 루비 V
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

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 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.\)

Problem credits: Yinzhan Xu

제약

BATCHING

  • Test cases 3-4 satisfy \(N\le 8.\)
  • Test cases 5-7 satisfy \(N\le 20.\)
  • Test cases 8-10 satisfy \(N\le 50.\)

Problem credits: Yinzhan Xu

입력 형식

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.\)

파일 입력 / 출력
이 문제는 표준 입출력을 사용하지 않습니다. 프로그램은 다음 파일을 읽고 써야 합니다:
입력을 읽을 파일 treedepth.in
출력을 쓸 파일 treedepth.out
예제 1
입력
3 0 192603497
출력
1 2 3 
설명

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

예제 2
입력
3 1 144408983
출력
3 4 4 
설명

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

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2019-2020 > December > Platinum

태그

평가 및 의견

Tree Depth

개요
출제자 난이도 Ruby V 루비 V 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Tree Depth

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8