No.1821 LEQ-GEQ Permutations
問題文最終更新日: 2022-01-21 18:57:42
English (AI translation)
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence.
Back to the original
yukicoder contest 328
(順位表)
の他の問題:
Problem Statement
You are given a string $S$ of length $N$ consisting of 0, 1.
Find the number, modulo $\bmod 998244353$, of pairs $(P,Q)$ of two permutations of length $N$ that satisfy the following condition.
- For every $i\ (1 \le i \le N)$, if $S_i =$
0then $P_i \leq Q_i$ holds, and if $S_i =$1then $P_i \geq Q_i$ holds.
Constraints
- $1\le N \le 5000$
- $S$ is a string of length $N$ consisting of
0,1.
Input
$N$ $S$
Output
Output the number, modulo $\bmod{998244353}$, of pairs $(P,Q)$ of two permutations of length $N$ that satisfy the condition.
Sample
Sample 1
Input
3 001
Output
14
The following $14$ pairs $(P,Q)$ satisfy the condition.
- $((1,2,3),(1,2,3))$
- $((1,2,3),(1,3,2))$
- $((1,2,3),(2,3,1))$
- $((1,2,3),(3,2,1))$
- $((1,3,2),(1,3,2))$
- $((1,3,2),(2,3,1))$
- $((2,1,3),(2,1,3))$
- $((2,1,3),(2,3,1))$
- $((2,1,3),(3,1,2))$
- $((2,1,3),(3,2,1))$
- $((2,3,1),(2,3,1))$
- $((3,1,2),(3,1,2))$
- $((3,1,2),(3,2,1))$
- $((3,2,1),(3,2,1))$
Sample 2
Input
3 111
Output
6
The following $6$ pairs $(P,Q)$ satisfy the condition.
- $((1,2,3),(1,2,3))$
- $((1,3,2),(1,3,2))$
- $((2,1,3),(2,1,3))$
- $((2,3,1),(2,3,1))$
- $((3,1,2),(3,1,2))$
- $((3,2,1),(3,2,1))$
Sample 3
Input
10 1010110001
Output
808663691
Note that the output must be taken modulo $\bmod 998244353$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
nok0
riano
sak