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.
Problems
It is time for the star of the show: a very big cake of size (n \times n). Alice and her friends want to decorate the cake with whipped cream in the shape of snakes. Define a snake of size (k) as a path of size (k) that starts at one cell of the cake and only goes down or right. Due to her extensive study of cake, Alice knows that the best way to decorate this cake is to place (n) snakes where the (i)-th snake has a size of (2 \cdot i - 1). She has prepared all the whipping cream beforehand; however, some of her friends are too excited and have already started placing some snakes on the cake before Alice could plan how exactly to decorate the cake. Fortunately, Alice finds that it is still possible to decorate the cake. Help her find the number of ways she can decorate the cake without moving any snake her friends had placed. Since the number of possible ways might be big, output it under modulo (10^9 + 7). Two configurations are different if there exists a cell that is occupied by a different snake. 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 first line of each test case contains two integers (n) and (k) ((1 \le n \le 5000, 0 \le k \le n)) — the size of the cake and the number of snakes that her friends had placed, respectively. The next (2 \cdot k) lines contain information about the (k) placed snakes. Each set of two consecutive lines contains the information about one of the placed snakes in the following manner. The first line contains integer (s) ((1 \le s \le 2\cdot n-1), (s) is odd) — the size of the snake. The second line contains (r), (c) ((1 \le r,c\le n)) — its starting row, and its starting column. Then, a string of length (s - 1) consisting only of the letters R and D where R means the next cell is to the right of the current cell, and D means |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
376744567 |
kochikamehoho |
E |
May 31, 2026, 6 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
50 |
46 |
102400 |
|
|
|
376733870 |
mangotree123 |
E |
May 31, 2026, 3:21 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
50 |
46 |
102400 |
|
|
|
376719650 |
_Filya_ |
E |
May 30, 2026, 8:28 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
50 |
46 |
102400 |
|
|
|
376718326 |
Taha90411 |
E |
May 30, 2026, 8:04 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
50 |
46 |
102400 |
|
|
|
376715082 |
gargshivam311201 |
E |
May 30, 2026, 7:14 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
50 |
46 |
102400 |
|
|
|
376699020 |
stateCompressed |
E |
May 30, 2026, 4:28 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
50 |
46 |
102400 |
|
|
|
376692719 |
zddtuus |
E |
May 30, 2026, 4:14 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
50 |
46 |
102400 |
|
|
|
376695422 |
GGJ001 |
E |
May 30, 2026, 4:20 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
50 |
46 |
17100800 |
|
|
|
376699186 |
_huanghongjun2012_ |
E |
May 30, 2026, 4:28 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
50 |
62 |
29696000 |
|
|
|
376734526 |
m1mirr |
E |
May 31, 2026, 3:35 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
50 |
78 |
102400 |
|
|
|
376711675 |
vedantkohad |
E |
May 30, 2026, 6:37 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
50 |
31 |
102400 |
|
|
|
376734756 |
CraaazyShep |
E |
May 31, 2026, 3:40 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
50 |
46 |
0 |
|
|
|
376735814 |
Cwulaek |
E |
May 31, 2026, 4:02 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
50 |
46 |
102400 |
|
|
|
376722360 |
vikram108 |
E |
May 30, 2026, 9:25 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
50 |
46 |
102400 |
|
|
|
376719226 |
Lalic |
E |
May 30, 2026, 8:20 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
50 |
46 |
102400 |
|
|
|
376704741 |
Abuseini |
E |
May 30, 2026, 5:27 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
50 |
46 |
102400 |
|
|
|
376695806 |
vikramgupta |
E |
May 30, 2026, 4:21 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
50 |
46 |
102400 |
|
|
|
376693102 |
yeminghan |
E |
May 30, 2026, 4:15 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
50 |
46 |
102400 |
|
|
|
376691544 |
Blind_Devil_769 |
E |
May 30, 2026, 4:11 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
50 |
46 |
102400 |
|
|
|
376714539 |
narges__ |
E |
May 30, 2026, 7:07 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
50 |
46 |
9625600 |
|
|
|
376739370 |
ZhouSihang |
E |
May 31, 2026, 4:47 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
50 |
46 |
0 |
|
|
|
376730909 |
haojiandan |
E |
May 31, 2026, 2:19 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
50 |
46 |
0 |
|
|
|
376726330 |
turkhuu622 |
E |
May 30, 2026, 11:40 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
50 |
46 |
0 |
|
|
|
376696176 |
PaperMemory |
E |
May 30, 2026, 4:22 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
50 |
46 |
0 |
|
|
|
376727339 |
DQ1275 |
E |
May 31, 2026, 12:26 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
50 |
46 |
102400 |
|
|
|
376722380 |
kv4yne |
E |
May 30, 2026, 9:26 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
50 |
46 |
102400 |
|
|
|
376706349 |
theumangkhatri |
E |
May 30, 2026, 5:43 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
50 |
46 |
102400 |
|
|
|
376704723 |
DanielChang |
E |
May 30, 2026, 5:27 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
50 |
46 |
102400 |
|
|
|
376701918 |
parkky |
E |
May 30, 2026, 4:33 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
50 |
46 |
102400 |
|
|
|
376694707 |
MartinRT |
E |
May 30, 2026, 4:19 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
50 |
46 |
102400 |
|
|
|
376706595 |
daniel.glabai |
E |
May 30, 2026, 5:45 p.m. |
OK |
Java 21 |
TESTS |
50 |
234 |
614400 |
|
|
|
376701280 |
Yoda1122 |
E |
May 30, 2026, 4:32 p.m. |
OK |
Java 21 |
TESTS |
50 |
234 |
921600 |
|
|
|
376695771 |
LT1 |
E |
May 30, 2026, 4:21 p.m. |
OK |
Java 21 |
TESTS |
50 |
265 |
819200 |
|
|
|
376701850 |
0xdaksh.12 |
E |
May 30, 2026, 4:33 p.m. |
OK |
Java 8 |
TESTS |
50 |
281 |
0 |
|
|
|
376709329 |
sos89756 |
E |
May 30, 2026, 6:13 p.m. |
OK |
PyPy 3 |
TESTS |
50 |
734 |
205516800 |
|
|
|
376717463 |
Pecky_Penguin |
E |
May 30, 2026, 7:50 p.m. |
OK |
PyPy 3-64 |
TESTS |
50 |
375 |
212377600 |
|
|
|
376700945 |
GKK26 |
E |
May 30, 2026, 4:31 p.m. |
OK |
PyPy 3-64 |
TESTS |
50 |
468 |
9216000 |
|
|
|
376728602 |
hxu10 |
E |
May 31, 2026, 1:16 a.m. |
OK |
PyPy 3-64 |
TESTS |
50 |
843 |
22630400 |
|
|
|
376728492 |
hxu10 |
E |
May 31, 2026, 1:12 a.m. |
OK |
PyPy 3-64 |
TESTS |
50 |
2156 |
204288000 |
|
|
|
376734172 |
_______________________ |
E |
May 31, 2026, 3:28 a.m. |
OK |
PyPy 3-64 |
TESTS |
50 |
2843 |
205004800 |
|
|
|
376710426 |
psun256 |
E |
May 30, 2026, 6:24 p.m. |
OK |
Rust 2024 |
TESTS |
50 |
62 |
11776000 |
|
|
remove filters
Back to search problems