| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 1024 MB | 14 | 9 | 9 | 90.000% |
While looking at the kitchen fridge, little boy Tyler noticed magnets with symbols, that can be aligned into a string $s$.
Tyler likes strings, and especially those that are lexicographically less than string $t$. After playing with magnets on the fridge he is wondering, how many distinct strings can be composed out of letters of string $s$ by rearranging them, so that the the resulting string is lexicographically less than string $t$. Tyler is studying only in the third grade, so he can not answer this question. Help him to calculate the number of permutations of letters of string $s,ドル that are lexicographically less than string $t$.
We call string $x$ lexicographically less than string $y$ if one of the followings conditions is fulfilled:
Because the answer can be too large, print it modulo 998ドル,244円,353円$.
The first line contains two integers $n$ and $m$ (1ドル \le n, m \le 200,000円$) --- lengths of strings $s$ and $t$.
The second line contains $n$ integers $s_1, s_2, s_3 \ldots s_n$ (1ドル \le s_i \le 200,000円$) --- symbols of string $s$.
The third line contains $m$ integers $t_1, t_2, t_3 \ldots t_m$ (1ドル \le t_i \le 200,000円$) --- symbols of string $t$.
Print the single integer --- the number of strings that are lexicographically less than $t,ドル that can be composed by rearranging letters of string $s$ modulo 998ドル,244円,353円$.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 16 | $n, m \le 10,ドル $s_i, t_i \le 10$ |
| 2 | 15 | $s_i, t_i \le 2$ |
| 3 | 11 | $s_i, t_i \le 20$ |
| 4 | 13 | $s_i, t_i \le 200$ |
| 5 | 12 | In each of the strings individually all symbols are distinct |
| 6 | 33 |
3 4 1 2 2 2 1 2 1
2
4 4 1 2 3 4 4 3 2 1
23
4 3 1 1 1 2 1 1 2
1
In the first sample, we should count strings [1 2 2] and [2 1 2]. String [2 2 1] is lexicographically grater than string [2 1 2 1], so we do not count it.
In the second sample we should count all strings except [4 3 2 1], so the answer is 4ドル! - 1 = 23$.
In the third sample we should count only string [1 1 1 2].
Olympiad > Moscow Open Olympiad in Informatics > Moscow Open Olympiad in Informatics 2021-22 > Day 2 C번