Codeforces Round 1077 (Div. 1)

Solutions are presented as using the least memory and the fastest execution time. It also takes the top 10 most recent solutions from each language. If you want to limit to a specific index, click the "Solved" button and go to that problem.

ContestId
Name
Phase
Frozen
Duration (Seconds)
Relative Time
Start Time
2187 Codeforces Round 1077 (Div. 1) FINISHED False 10800 6708323 Jan. 29, 2026, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 65 ) F2 Al Fine (Counting Version) PROGRAMMING dp trees

This is the counting version of the problem. The difference between the versions is that in this version, you need to find the number of different common trees. Also, the constraint on (n) in this version is smaller. You can hack only if you solved all versions of this problem. For Christmas, Tortinita and Arietta each get a Christmas tree. Coincidentally, their trees share the same properties: both have (n+1) vertices and are rooted at vertex (0). In their Christmas card to you, each of them appends a DFS order sequence of their tree after their greetings. Recall that a DFS order sequence is generated by the following pseudocode. Let the DFS order sequence of Tortinita's tree be (a_0, a_1, \ldots, a_n) and that of Arietta's tree be (b_0, b_1, \ldots, b_n). You observe that (a_0 = b_0 = 0), and since they are twin sisters, you wonder if they could have the exact same tree. Therefore, you want to find the number of different common trees(^{\text{∗}}) for both sequences . Since the answer may be very large, you need to output it modulo (998\,244\,353). (^{\text{∗}})Two trees are considered different if there exists a vertex label for which the set of its children's labels is not identical in both trees. In other words, the ordering of children for any given vertex does not matter. Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 10^4)). The description of the test cases follows. The first line of each test case contains one integer (n) ((2 \le n \le \boldsymbol{5000})). The second line of each test case contains (n) integers (a_1, a_2, \cdots, a_n) ((1 \le a_i \le n)). The third line of each test case contains (n) integers (b_1, b_2, \cdots, b_n) ((1 \le b_i \le n)). It is guaranteed that neither sequence (a) nor (b) contains duplicates. It is guaranteed that the sum of (n^2) over all test cases does not exceed $$$

Tutorials

Codeforces Round 1077 (Div. 1, Div. 2) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
360651961 Legend_of_Bangladesh F2 Jan. 30, 2026, 2:17 a.m. OK C++23 (GCC 14-64, msys2) TESTS 58 265 25292800
360645084 Szoboszlai10 F2 Jan. 29, 2026, 11:09 p.m. OK C++23 (GCC 14-64, msys2) TESTS 58 265 25395200
360598425 ecnerwala F2 Jan. 29, 2026, 4:50 p.m. OK C++23 (GCC 14-64, msys2) TESTS 58 281 0
360645165 peti1234 F2 Jan. 29, 2026, 11:11 p.m. OK C++23 (GCC 14-64, msys2) TESTS 58 281 25292800
360598887 Nachia F2 Jan. 29, 2026, 4:51 p.m. OK C++23 (GCC 14-64, msys2) TESTS 58 406 0
360614838 maroonrk F2 Jan. 29, 2026, 5:32 p.m. OK C++23 (GCC 14-64, msys2) TESTS 58 421 42086400
360644968 ko_osaga F2 Jan. 29, 2026, 11:07 p.m. OK C++23 (GCC 14-64, msys2) TESTS 58 468 65843200
360623848 maspy F2 Jan. 29, 2026, 6:39 p.m. OK C++23 (GCC 14-64, msys2) TESTS 58 500 162508800
360666768 DivineLife F2 Jan. 30, 2026, 5:38 a.m. OK C++23 (GCC 14-64, msys2) TESTS 58 609 102400
360622594 hos.lyric F2 Jan. 29, 2026, 6:30 p.m. OK C++23 (GCC 14-64, msys2) TESTS 58 671 65433600

remove filters

Back to search problems