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
This is the easy version of the problem. The difference between the versions is that in this version, the constraints on (t) and (n) are smaller. You can hack only if you solved all versions of this problem. Maple is given a rooted tree consisting of (n) vertices numbered from (1) to (n), where the root has index (1). Each vertex of the tree is labeled either zero or one. Unfortunately, Maple forgot how the vertices are labeled and only remembers that there are exactly (k) zeros and (n - k) ones. For each vertex, we define the name of the vertex as the binary string formed by concatenating the labels of the vertices from the root to the vertex. More formally, (\text{name}_1 = \text{label}_1) and (\text{name}_u = \text{name}_{p_u} + \text{label}_u) for all (2\le u\le n), where (p_u) is the parent of vertex (u) and (+) represents string concatenation. The beauty of the tree is equal to the length of the longest common subsequence(^{\text{∗}}) of the names of all the leaves (^{\text{†}}). Your task is to determine the maximum beauty among all labelings of the tree with exactly (k) zeros and (n - k) ones. (^{\text{∗}})A sequence (a) is a subsequence of a sequence (b) if (a) can be obtained from (b) by the deletion of several (possibly, zero or all) element from arbitrary positions. The longest common subsequence of strings (s_1, s_2, \ldots s_m) is the longest string that is a subsequence of all of (s_1, s_2, \ldots, s_m). (^{\text{†}})A leaf is any vertex without children. Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 50)). The description of the test cases follows. The first line of each test case contains two integers (n) and (k) ((2 \leq n \leq 1000), (0 \leq k \leq n)) — the number of vertices and the number of vertices labeled with zero, respectively. The second line c |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
337688193 |
wifiiii |
C1 |
Sept. 9, 2025, 1:48 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
69 |
62 |
102400 |
|
|
|
337690385 |
lesunhan2022 |
C1 |
Sept. 9, 2025, 2:27 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
70 |
62 |
2457600 |
|
|
|
337692705 |
8Conan8 |
C1 |
Sept. 9, 2025, 3:02 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
70 |
62 |
5632000 |
|
|
|
337705345 |
Iced_Orange_Juice |
C1 |
Sept. 9, 2025, 5:59 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
72 |
77 |
0 |
|
|
|
337671140 |
chatgpt_pro_max |
C1 |
Sept. 8, 2025, 7:46 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
67 |
77 |
0 |
|
|
|
337653164 |
TiLTovozzik |
C1 |
Sept. 8, 2025, 5:11 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
67 |
77 |
0 |
|
|
|
337617485 |
ivandasfs |
C1 |
Sept. 8, 2025, 3:47 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
67 |
77 |
102400 |
|
|
|
337650438 |
ling_chen |
C1 |
Sept. 8, 2025, 5:03 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
67 |
77 |
2662400 |
|
|
|
337612081 |
Az3ar |
C1 |
Sept. 8, 2025, 3:38 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
67 |
77 |
4505600 |
|
|
|
337609735 |
xuemanowo |
C1 |
Sept. 8, 2025, 3:34 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
67 |
77 |
5632000 |
|
|
|
337689273 |
classic |
C1 |
Sept. 9, 2025, 2:09 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
69 |
61 |
0 |
|
|
|
337687845 |
classic |
C1 |
Sept. 9, 2025, 1:42 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
69 |
62 |
102400 |
|
|
|
337599847 |
Tom66 |
C1 |
Sept. 8, 2025, 3:18 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
67 |
62 |
3276800 |
|
|
|
337671553 |
Ormlis |
C1 |
Sept. 8, 2025, 7:51 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
67 |
77 |
102400 |
|
|
|
337654325 |
NotOnlySuccess |
C1 |
Sept. 8, 2025, 5:15 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
67 |
77 |
102400 |
|
|
|
337653917 |
Omar_Mohammad |
C1 |
Sept. 8, 2025, 5:13 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
67 |
77 |
102400 |
|
|
|
337643746 |
Frus |
C1 |
Sept. 8, 2025, 4:45 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
67 |
77 |
102400 |
|
|
|
337641312 |
kh0i |
C1 |
Sept. 8, 2025, 4:38 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
67 |
77 |
102400 |
|
|
|
337637894 |
toam |
C1 |
Sept. 8, 2025, 4:30 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
67 |
77 |
102400 |
|
|
|
337637810 |
sahaun |
C1 |
Sept. 8, 2025, 4:30 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
67 |
77 |
102400 |
|
|
|
337691166 |
huy_pr |
C1 |
Sept. 9, 2025, 2:39 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
70 |
62 |
0 |
|
|
|
337696452 |
shreehithagopavaram |
C1 |
Sept. 9, 2025, 3:56 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
72 |
62 |
102400 |
|
|
|
337696122 |
Andrew_sun |
C1 |
Sept. 9, 2025, 3:50 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
72 |
62 |
102400 |
|
|
|
337693121 |
sarbansah0410 |
C1 |
Sept. 9, 2025, 3:08 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
70 |
62 |
102400 |
|
|
|
337691882 |
donghaocheng |
C1 |
Sept. 9, 2025, 2:50 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
70 |
62 |
102400 |
|
|
|
337649114 |
Atziluth |
C1 |
Sept. 8, 2025, 4:59 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
67 |
62 |
4096000 |
|
|
|
337693490 |
LUVK |
C1 |
Sept. 9, 2025, 3:13 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
70 |
62 |
16588800 |
|
|
|
337695237 |
abc864197532 |
C1 |
Sept. 9, 2025, 3:38 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
72 |
77 |
0 |
|
|
|
337659758 |
Endagorion |
C1 |
Sept. 8, 2025, 5:32 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
67 |
77 |
0 |
|
|
|
337637451 |
Void_Wu |
C1 |
Sept. 8, 2025, 4:29 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
67 |
77 |
0 |
|
|
|
337625981 |
pengin_2000 |
C1 |
Sept. 8, 2025, 4:04 p.m. |
OK |
GNU C11 |
TESTS |
67 |
186 |
102400 |
|
|
|
337691811 |
Balu2907 |
C1 |
Sept. 9, 2025, 2:49 a.m. |
OK |
Java 21 |
TESTS |
70 |
296 |
1024000 |
|
|
|
337669470 |
MaxBuzz |
C1 |
Sept. 8, 2025, 7:28 p.m. |
OK |
Java 21 |
TESTS |
67 |
296 |
1536000 |
|
|
|
337672883 |
Balu2907 |
C1 |
Sept. 8, 2025, 8:07 p.m. |
OK |
Java 21 |
TESTS |
67 |
311 |
1536000 |
|
|
|
337670822 |
shivansh_123 |
C1 |
Sept. 8, 2025, 7:43 p.m. |
OK |
Java 21 |
TESTS |
67 |
327 |
1843200 |
|
|
|
337683102 |
ccj123 |
C1 |
Sept. 8, 2025, 11:55 p.m. |
OK |
Java 21 |
TESTS |
69 |
452 |
1024000 |
|
|
|
337581243 |
sunnydev |
C1 |
Sept. 8, 2025, 2:54 p.m. |
OK |
Java 8 |
TESTS |
67 |
187 |
0 |
|
|
|
337605988 |
iakovlev.zakhar |
C1 |
Sept. 8, 2025, 3:28 p.m. |
OK |
Java 8 |
TESTS |
67 |
233 |
0 |
|
|
|
337631236 |
SPD_9X2 |
C1 |
Sept. 8, 2025, 4:15 p.m. |
OK |
PyPy 3 |
TESTS |
67 |
483 |
14028800 |
|
|
|
337685359 |
alexwice |
C1 |
Sept. 9, 2025, 12:49 a.m. |
OK |
PyPy 3-64 |
TESTS |
69 |
124 |
9216000 |
|
|
|
337639329 |
bcollet |
C1 |
Sept. 8, 2025, 4:33 p.m. |
OK |
PyPy 3-64 |
TESTS |
67 |
171 |
4403200 |
|
|
|
337599676 |
golomb |
C1 |
Sept. 8, 2025, 3:18 p.m. |
OK |
PyPy 3-64 |
TESTS |
67 |
171 |
4812800 |
|
|
|
337638540 |
LMeyling |
C1 |
Sept. 8, 2025, 4:31 p.m. |
OK |
PyPy 3-64 |
TESTS |
67 |
171 |
9420800 |
|
|
|
337628567 |
ow3nL |
C1 |
Sept. 8, 2025, 4:09 p.m. |
OK |
PyPy 3-64 |
TESTS |
67 |
187 |
8806400 |
|
|
|
337606152 |
eepsilon |
C1 |
Sept. 8, 2025, 3:28 p.m. |
OK |
PyPy 3-64 |
TESTS |
67 |
202 |
4403200 |
|
|
|
337624682 |
smilences |
C1 |
Sept. 8, 2025, 4:01 p.m. |
OK |
PyPy 3-64 |
TESTS |
67 |
280 |
6246400 |
|
|
|
337703498 |
siuhou |
C1 |
Sept. 9, 2025, 5:36 a.m. |
OK |
PyPy 3-64 |
TESTS |
72 |
281 |
4608000 |
|
|
|
337634917 |
Mukundan314 |
C1 |
Sept. 8, 2025, 4:23 p.m. |
OK |
PyPy 3-64 |
TESTS |
67 |
327 |
8601600 |
|
|
|
337626663 |
twosquares |
C1 |
Sept. 8, 2025, 4:05 p.m. |
OK |
PyPy 3-64 |
TESTS |
67 |
390 |
9113600 |
|
|
|
337600673 |
sansen |
C1 |
Sept. 8, 2025, 3:19 p.m. |
OK |
Rust 2021 |
TESTS |
67 |
77 |
102400 |
|
|
|
337588695 |
Sugar_fan |
C1 |
Sept. 8, 2025, 3:02 p.m. |
OK |
Rust 2024 |
TESTS |
67 |
93 |
0 |
|
|
|
337644528 |
Ming_Xu |
C1 |
Sept. 8, 2025, 4:47 p.m. |
OK |
Rust 2024 |
TESTS |
67 |
124 |
102400 |
|
|
|
337634546 |
WaterColor2037 |
C1 |
Sept. 8, 2025, 4:22 p.m. |
OK |
Rust 2024 |
TESTS |
67 |
358 |
102400 |
|
|
remove filters
Back to search problems