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

28205번 - Classical DP Problem 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB126673646.154%

문제

Let us consider a grid of squares with $n$ rows and $n$ columns. Arbok has cut out some part of the grid so that, for each $i = 1, 2, \ldots, n,ドル only the leftmost $a_i$ squares are remaining in the $i$-th row from the top. The values of $a_i$ satisfy $a_1 \le a_2 \le \ldots \le a_n$: that is, the grid looks like a Young diagram. Now, Arbok wants to place rooks into some of the remaining squares of the grid.

A rook is a chess piece that occupies one square and can move horizontally or vertically, through any number of unoccupied squares.

Let's say that a square is covered if it either contains a rook, or a rook can be moved to this square in one move.

Find $r,ドル the smallest number of rooks Arbok needs to place into some of the remaining squares so that every remaining square is covered. Also find $w,ドル the number of ways to put $r$ rooks to satisfy the same condition, modulo 998ドル,244円,353円$.

입력

The first line contains a single integer $n,ドル denoting the size of the grid (1ドル \le n \le 5000$).

The second line contains $n$ integers $a_1, a_2, \ldots, a_n,ドル denoting the widths of the rows left by Arbok (1ドル \le a_1 \le a_2 \le \ldots \le a_n \le n$).

출력

Print two integers $r$ and $w,ドル denoting the smallest number of rooks Arbok needs to place so that every remaining square is covered, and the number of ways to put $r$ rooks to achieve the same, modulo 998ドル,244円,353円$.

제한

예제 입력 1

3
1 2 3

예제 출력 1

2 6

노트

In the first example test, one rook is not enough to cover every square, but two rooks are enough, and there are six ways to place two rooks to cover every square (R denotes a rook, * denotes an empty square):

R * * * * * 
** R* R* R* *R ** 
*R* R** *R* **R R** RR*

출처

Camp > Petrozavodsk Programming Camp > Winter 2023 > Day 7: Gennady Korotkevich Contest 7 D번

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

출처

대학교 대회

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

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