Codeforces Round 1035 (Div. 2)

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
2119 Codeforces Round 1035 (Div. 2) FINISHED False 7200 24679522 July 5, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 3412 ) D Token Removing PROGRAMMING combinatorics dp math

Define a sequence of integers (a) valid if and only if (\forall 1 \le i \le n, 0 \le a_i \le i). Define the weight (f(a)) of a valid sequence (a) of length (n): Initially, a token is placed at each integer point in the closed segment (1, n) on the number axis. Perform (n) operations in sequence. During the (i)-th operation, if (a_i \ne 0), remove a token in the closed segment (a_i, i) that has not been removed; otherwise, do nothing. (f(a)) is the number of ways to remove tokens. Two ways are considered different if there exists a (t) such that the positions of the tokens removed by the two ways are different at the (t)-th operation. For example, (f(0, 2, 1) = 2), because we can remove tokens on (2, 1) or (2, 3) in sequence. JT gives you two integers (n, m) and asks you to find the sum of the weight s over all ((n + 1)!) valid sequences of length (n). Since the answer may be too large, print it modulo (m). Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 1000)). The description of the test cases follows. The only line of each test case contains two integers (n) and (m) ((1 \le n \le 5000, 10^8 \le m \le 1.01 \cdot 10^9)) — the length of valid sequences, and the modulus. It is guaranteed that the sum of (n^2) over all test cases does not exceed (2.5 \cdot 10^7). For each test case, output an integer — the sum of the weight s over all ((n + 1)!) valid sequences of length (n), modulo (m). In the first test case, valid sequences are (0) and (1), and the answer is (f(0) + f(1) = 1 + 1 = 2). In the second test case, valid sequences are (0, 0, 0, 1, 0, 2, 1, 0, 1, 1, 1, 2). The weight of (0, 1) is (2), and the others are (1), so the answer is (5 \cdot 1 + 1 \cdot 2 = 7).

Tutorials

Codeforces Round 1035 (Div. 2) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
327662206 runde D July 6, 2025, 2:47 a.m. OK C++17 (GCC 7-32) TESTS 20 202 201216000
327664335 Gui_Yu D July 6, 2025, 3:22 a.m. OK C++17 (GCC 7-32) TESTS 20 203 0
327618716 om_swarup D July 5, 2025, 4:27 p.m. OK C++17 (GCC 7-32) TESTS 20 234 0
327613844 Premsanthosh16 D July 5, 2025, 4:17 p.m. OK C++17 (GCC 7-32) TESTS 20 234 102400
327617312 devanshiiitl D July 5, 2025, 4:25 p.m. OK C++17 (GCC 7-32) TESTS 20 265 0
327620762 chenweilian D July 5, 2025, 4:31 p.m. OK C++17 (GCC 7-32) TESTS 20 265 102400
327620461 Athk_0312 D July 5, 2025, 4:31 p.m. OK C++17 (GCC 7-32) TESTS 20 265 102400
327615131 SeaP D July 5, 2025, 4:20 p.m. OK C++17 (GCC 7-32) TESTS 20 265 102400
327622187 _nidhish_ D July 5, 2025, 4:34 p.m. OK C++17 (GCC 7-32) TESTS 20 280 102400
327618251 Mennah_fathy_gadalla D July 5, 2025, 4:26 p.m. OK C++17 (GCC 7-32) TESTS 20 280 102400
327625096 _shin D July 5, 2025, 5:09 p.m. OK C++20 (GCC 13-64) TESTS 20 156 102400
327671915 bebopboi D July 6, 2025, 5:24 a.m. OK C++20 (GCC 13-64) TESTS 20 186 102400
327616575 __baozii__ D July 5, 2025, 4:23 p.m. OK C++20 (GCC 13-64) TESTS 20 218 102400
327613720 komite D July 5, 2025, 4:17 p.m. OK C++20 (GCC 13-64) TESTS 20 218 102400
327660139 hyprox D July 6, 2025, 2:13 a.m. OK C++20 (GCC 13-64) TESTS 20 233 0
327615982 hopefull_61 D July 5, 2025, 4:22 p.m. OK C++20 (GCC 13-64) TESTS 20 233 102400
327648363 shiinamashiro_ D July 5, 2025, 8:51 p.m. OK C++20 (GCC 13-64) TESTS 20 234 102400
327653215 kkzyr D July 5, 2025, 10:42 p.m. OK C++20 (GCC 13-64) TESTS 20 234 200806400
327650420 littlebluepenguins D July 5, 2025, 9:30 p.m. OK C++20 (GCC 13-64) TESTS 20 249 102400
327659071 anke2017 D July 6, 2025, 1:47 a.m. OK C++20 (GCC 13-64) TESTS 20 250 102400
327654711 Bullet D July 5, 2025, 11:30 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 140 0
327636424 iantsai0616 D July 5, 2025, 6:37 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 155 0
327662753 jianjianj D July 6, 2025, 2:56 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 171 102400
327629689 C0DET1GER D July 5, 2025, 5:41 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 171 102400
327614730 xmrozny D July 5, 2025, 4:19 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 171 102400
327621967 hskyr D July 5, 2025, 4:34 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 187 102400
327628929 73501 D July 5, 2025, 5:35 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 202 200908800
327629352 Void_Wu D July 5, 2025, 5:39 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 217 0
327631484 awol777 D July 5, 2025, 5:56 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 218 97280000
327666590 nobodyinfact D July 6, 2025, 4:01 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 233 0
327653043 lyongwolf D July 5, 2025, 10:38 p.m. OK Java 21 TESTS 20 405 716800
327613713 Yoda1122 D July 5, 2025, 4:17 p.m. OK Java 21 TESTS 20 515 614400
327652978 lyongwolf D July 5, 2025, 10:36 p.m. OK Java 21 TESTS 20 593 262860800
327631491 sahasrad D July 5, 2025, 5:56 p.m. OK Java 21 TESTS 20 624 1638400
327627955 priyaroy3370 D July 5, 2025, 5:29 p.m. OK Java 21 TESTS 20 655 921600
327620633 practiceDaily2 D July 5, 2025, 4:31 p.m. OK Java 21 TESTS 20 656 1126400
327626955 Eigen_Value D July 5, 2025, 5:22 p.m. OK Java 21 TESTS 20 671 1228800
327618137 kovvurilaxmanaditya D July 5, 2025, 4:26 p.m. OK Java 21 TESTS 20 718 1126400
327656773 wddd D July 6, 2025, 12:42 a.m. OK Java 21 TESTS 20 796 260915200
327630102 sahasrad D July 5, 2025, 5:44 p.m. OK Java 21 TESTS 20 937 261222400
327622049 Shashwata_32 D July 5, 2025, 4:34 p.m. OK Java 8 TESTS 20 374 17100800
327621731 Divyanshu_Lila D July 5, 2025, 4:33 p.m. OK Java 8 TESTS 20 640 0
327616226 DonCP D July 5, 2025, 4:22 p.m. OK Java 8 TESTS 20 686 0
327620275 maharshi.raval05 D July 5, 2025, 4:30 p.m. OK Java 8 TESTS 20 687 0
327630328 kasiru_69 D July 5, 2025, 5:46 p.m. OK Java 8 TESTS 20 1218 260403200
327616303 ultron513 D July 5, 2025, 4:22 p.m. OK PHP TESTS 20 1624 307200
327659615 alexwice D July 6, 2025, 2:01 a.m. OK PyPy 3-64 TESTS 20 265 2764800
327624521 sushmanth.dampur8780 D July 5, 2025, 5:06 p.m. OK PyPy 3-64 TESTS 20 296 2252800
327625654 lan246 D July 5, 2025, 5:13 p.m. OK PyPy 3-64 TESTS 20 311 2150400
327670187 Huygd D July 6, 2025, 4:59 a.m. OK PyPy 3-64 TESTS 20 312 3072000
327661893 AnonyLeo D July 6, 2025, 2:43 a.m. OK PyPy 3-64 TESTS 20 312 3584000
327660157 siuhou D July 6, 2025, 2:13 a.m. OK PyPy 3-64 TESTS 20 421 6963200
327620133 Praneethrcls D July 5, 2025, 4:30 p.m. OK PyPy 3-64 TESTS 20 437 2457600
327657967 Little_Sheep_Yawn D July 6, 2025, 1:16 a.m. OK PyPy 3-64 TESTS 20 452 10444800
327613765 pranprocodes D July 5, 2025, 4:17 p.m. OK PyPy 3-64 TESTS 20 467 2764800
327626686 kvedula2004 D July 5, 2025, 5:20 p.m. OK PyPy 3-64 TESTS 20 484 102707200

remove filters

Back to search problems