시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 512 MB | 40 | 30 | 23 | 85.185% |
You are given a bipartite graph with n vertices in each part.
In this graph, each vertex from the left part is connected to some prefix of vertices from the right part. Namely, the i-th vertex in the left part is connected with vertices 1, 2, . . . , ai in the right part.
Find the number of vertex-simple cycles in this graph. Two cycles are different if there exists some edge which is present in one cycle but not in the other.
As this number may be large, find it modulo 998 244 353.
The first line of input contains one integer n (1 ≤ n ≤ 5000): the number of vertices in each part.
The next line of input contains n integers a1, a2, . . . , an (1 ≤ ai ≤ n): a description of the given graph.
Output one integer: the number of vertex-simple cycles in the given graph, modulo 998 244 353.
1 1
0
2 2 2
1
3 3 3 2
7
10 6 6 7 7 8 8 9 9 10 10
410150080
Camp > Petrozavodsk Programming Camp > Winter 2020 > Day 3: 300iq Petrozavodsk Contest III H번