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
B'You are given two integers n and d . You need to construct a rooted binary tree consisting of n vertices with a root at the vertex 1 and the sum of depths of all vertices equals to d . A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. A parent of a vertex v is the last different from v vertex on the path from the root to the vertex v . The depth of the vertex v is the length of the path from the root to the vertex v . Children of vertex v are all vertices for which v is the parent. The binary tree is such a tree that no vertex has more than 2 children. You have to answer t independent test cases. The first line of the input contains one integer t ( 1 <= t <= 1000 ) -- the number of test cases. The only line of each test case contains two integers n and d ( 2 <= n, d <= 5000 ) -- the number of vertices in the tree and the required sum of depths of all vertices. It is guaranteed that the sum of n and the sum of d both does not exceed 5000 ( sum n <= 5000, sum d <= 5000 ). For each test case, print the answer. If it is impossible to construct such a tree, print "NO" (without quotes) in the first line. Otherwise, print "{YES}" in the first line. Then print n-1 integers p_2, p_3, ... , p_n in the second line, where p_i is the parent of the vertex i . Note that the sequence of parents you print should describe some binary tree. Pictures corresponding to the first and the second test cases of the example: '... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
71836091 |
ftiasch |
E |
Feb. 25, 2020, 5:35 a.m. |
OK |
D |
TESTS |
33 |
31 |
4198400 |
|
2400 |
71896999 |
561561561 |
E |
Feb. 26, 2020, 6:04 a.m. |
OK |
GNU C11 |
TESTS |
33 |
31 |
0 |
|
2400 |
71788088 |
rainboy |
E |
Feb. 24, 2020, 3:16 p.m. |
OK |
GNU C11 |
TESTS |
33 |
31 |
0 |
|
2400 |
71897204 |
561561561 |
E |
Feb. 26, 2020, 6:10 a.m. |
OK |
GNU C11 |
TESTS |
33 |
46 |
0 |
|
2400 |
71923054 |
jintiandun |
E |
Feb. 26, 2020, 3:22 p.m. |
OK |
GNU C++11 |
TESTS |
33 |
31 |
0 |
|
2400 |
71922413 |
ydhjuruo |
E |
Feb. 26, 2020, 3:11 p.m. |
OK |
GNU C++11 |
TESTS |
33 |
31 |
0 |
|
2400 |
71912866 |
YHHxBULIATANIA |
E |
Feb. 26, 2020, 12:22 p.m. |
OK |
GNU C++11 |
TESTS |
33 |
31 |
0 |
|
2400 |
71900582 |
gyh20 |
E |
Feb. 26, 2020, 7:39 a.m. |
OK |
GNU C++11 |
TESTS |
33 |
31 |
0 |
|
2400 |
71893729 |
ix35 |
E |
Feb. 26, 2020, 4:05 a.m. |
OK |
GNU C++11 |
TESTS |
33 |
31 |
0 |
|
2400 |
71888406 |
guptagovind1303 |
E |
Feb. 26, 2020, 12:01 a.m. |
OK |
GNU C++11 |
TESTS |
33 |
31 |
0 |
|
2400 |
71871062 |
aison |
E |
Feb. 25, 2020, 4:15 p.m. |
OK |
GNU C++11 |
TESTS |
33 |
31 |
0 |
|
2400 |
71923127 |
jintiandun |
E |
Feb. 26, 2020, 3:24 p.m. |
OK |
GNU C++11 |
TESTS |
33 |
31 |
0 |
|
2400 |
71947273 |
Mister_TT |
E |
Feb. 27, 2020, 2:49 a.m. |
OK |
GNU C++11 |
TESTS |
33 |
31 |
0 |
|
2400 |
71923254 |
ydh |
E |
Feb. 26, 2020, 3:26 p.m. |
OK |
GNU C++11 |
TESTS |
33 |
31 |
0 |
|
2400 |
71799884 |
I_AM_SOOKE_I_AKed_IOI |
E |
Feb. 24, 2020, 3:56 p.m. |
OK |
GNU C++14 |
TESTS |
33 |
15 |
0 |
|
2400 |
71804160 |
theStaticMind |
E |
Feb. 24, 2020, 4:13 p.m. |
OK |
GNU C++14 |
TESTS |
33 |
15 |
204800 |
|
2400 |
71807622 |
fragusbot |
E |
Feb. 24, 2020, 4:28 p.m. |
OK |
GNU C++14 |
TESTS |
33 |
30 |
0 |
|
2400 |
71835646 |
Charles1999 |
E |
Feb. 25, 2020, 5:23 a.m. |
OK |
GNU C++14 |
TESTS |
33 |
30 |
102400 |
|
2400 |
71832947 |
goatzyq |
E |
Feb. 25, 2020, 4 a.m. |
OK |
GNU C++14 |
TESTS |
33 |
30 |
102400 |
|
2400 |
71831720 |
Turkey |
E |
Feb. 25, 2020, 3:16 a.m. |
OK |
GNU C++14 |
TESTS |
33 |
30 |
102400 |
|
2400 |
71946605 |
carcar |
E |
Feb. 27, 2020, 2:23 a.m. |
OK |
GNU C++14 |
TESTS |
33 |
30 |
102400 |
|
2400 |
71857365 |
emanlaicepsa |
E |
Feb. 25, 2020, 12:40 p.m. |
OK |
GNU C++14 |
TESTS |
33 |
30 |
102400 |
|
2400 |
71843232 |
linesekarenge |
E |
Feb. 25, 2020, 8:14 a.m. |
OK |
GNU C++14 |
TESTS |
33 |
30 |
102400 |
|
2400 |
71860492 |
AcceptedMonster |
E |
Feb. 25, 2020, 1:27 p.m. |
OK |
GNU C++14 |
TESTS |
33 |
30 |
204800 |
|
2400 |
71907327 |
DDDoimate |
E |
Feb. 26, 2020, 10:31 a.m. |
OK |
GNU C++17 |
TESTS |
33 |
15 |
102400 |
|
2400 |
71846584 |
zzxzxzzxz |
E |
Feb. 25, 2020, 9:25 a.m. |
OK |
GNU C++17 |
TESTS |
33 |
15 |
204800 |
|
2400 |
71805968 |
Hasan0540 |
E |
Feb. 24, 2020, 4:21 p.m. |
OK |
GNU C++17 |
TESTS |
33 |
15 |
204800 |
|
2400 |
71877274 |
Nihad_Nabelsi |
E |
Feb. 25, 2020, 6:13 p.m. |
OK |
GNU C++17 |
TESTS |
33 |
15 |
204800 |
|
2400 |
71799762 |
Felerius |
E |
Feb. 24, 2020, 3:55 p.m. |
OK |
GNU C++17 |
TESTS |
33 |
15 |
409600 |
|
2400 |
71854316 |
ccsu_YangJ |
E |
Feb. 25, 2020, 11:51 a.m. |
OK |
GNU C++17 |
TESTS |
33 |
30 |
0 |
|
2400 |
71801516 |
BizansTekmesi |
E |
Feb. 24, 2020, 4:02 p.m. |
OK |
GNU C++17 |
TESTS |
33 |
30 |
0 |
|
2400 |
71860142 |
Manel_Nesquik |
E |
Feb. 25, 2020, 1:22 p.m. |
OK |
GNU C++17 |
TESTS |
33 |
30 |
0 |
|
2400 |
71900104 |
Yzm007 |
E |
Feb. 26, 2020, 7:26 a.m. |
OK |
GNU C++17 |
TESTS |
33 |
30 |
0 |
|
2400 |
71905843 |
seekluna_xrc |
E |
Feb. 26, 2020, 9:58 a.m. |
OK |
GNU C++17 |
TESTS |
33 |
30 |
0 |
|
2400 |
71880435 |
mikkk |
E |
Feb. 25, 2020, 7:21 p.m. |
OK |
Java 11 |
TESTS |
33 |
202 |
0 |
|
2400 |
71843962 |
adamjamil |
E |
Feb. 25, 2020, 8:29 a.m. |
OK |
Java 11 |
TESTS |
33 |
202 |
0 |
|
2400 |
71793334 |
TheSawan |
E |
Feb. 24, 2020, 3:31 p.m. |
OK |
Java 11 |
TESTS |
33 |
202 |
0 |
|
2400 |
71793153 |
uwi |
E |
Feb. 24, 2020, 3:31 p.m. |
OK |
Java 11 |
TESTS |
33 |
202 |
0 |
|
2400 |
71801038 |
Dukkha |
E |
Feb. 24, 2020, 4 p.m. |
OK |
Java 11 |
TESTS |
33 |
233 |
0 |
|
2400 |
71923868 |
AshrafEzz |
E |
Feb. 26, 2020, 3:36 p.m. |
OK |
Java 11 |
TESTS |
33 |
374 |
18329600 |
|
2400 |
71879384 |
prem_cse |
E |
Feb. 25, 2020, 6:57 p.m. |
OK |
Java 8 |
TESTS |
33 |
124 |
0 |
|
2400 |
71826611 |
icpc_loser |
E |
Feb. 24, 2020, 10:59 p.m. |
OK |
Java 8 |
TESTS |
33 |
124 |
0 |
|
2400 |
71824548 |
lzhang |
E |
Feb. 24, 2020, 9:33 p.m. |
OK |
Java 8 |
TESTS |
33 |
124 |
0 |
|
2400 |
71814000 |
_apurv_ |
E |
Feb. 24, 2020, 5:25 p.m. |
OK |
Java 8 |
TESTS |
33 |
124 |
0 |
|
2400 |
71802164 |
Hemose |
E |
Feb. 24, 2020, 4:05 p.m. |
OK |
Java 8 |
TESTS |
33 |
124 |
0 |
|
2400 |
71796136 |
Taran_1407 |
E |
Feb. 24, 2020, 3:41 p.m. |
OK |
Java 8 |
TESTS |
33 |
156 |
0 |
|
2400 |
71874783 |
ktflix2811 |
E |
Feb. 25, 2020, 5:22 p.m. |
OK |
Java 8 |
TESTS |
33 |
529 |
0 |
|
2400 |
71863397 |
KharYusuf |
E |
Feb. 25, 2020, 2:11 p.m. |
OK |
Java 8 |
TESTS |
33 |
530 |
0 |
|
2400 |
71955665 |
Sashik |
E |
Feb. 27, 2020, 7 a.m. |
OK |
Java 8 |
TESTS |
33 |
561 |
0 |
|
2400 |
71965673 |
Fortin |
E |
Feb. 27, 2020, 10:31 a.m. |
OK |
Kotlin |
TESTS |
33 |
124 |
0 |
|
2400 |
71949270 |
Benq |
E |
Feb. 27, 2020, 4:04 a.m. |
OK |
Kotlin |
TESTS |
33 |
155 |
0 |
|
2400 |
71839285 |
lucifer1004 |
E |
Feb. 25, 2020, 6:49 a.m. |
OK |
Kotlin |
TESTS |
33 |
171 |
1331200 |
|
2400 |
71786244 |
riantkb |
E |
Feb. 24, 2020, 3:11 p.m. |
OK |
Mono C# |
TESTS |
33 |
61 |
102400 |
|
2400 |
71821449 |
T-D-K |
E |
Feb. 24, 2020, 7:52 p.m. |
OK |
Mono C# |
TESTS |
33 |
62 |
102400 |
|
2400 |
71811094 |
r57shell |
E |
Feb. 24, 2020, 4:49 p.m. |
OK |
MS C++ |
TESTS |
33 |
31 |
0 |
|
2400 |
71811049 |
danilgrig |
E |
Feb. 24, 2020, 4:49 p.m. |
OK |
MS C++ |
TESTS |
33 |
31 |
204800 |
|
2400 |
71889231 |
re_eVVorld |
E |
Feb. 26, 2020, 12:47 a.m. |
OK |
MS C++ 2017 |
TESTS |
33 |
31 |
307200 |
|
2400 |
71793364 |
pichulia |
E |
Feb. 24, 2020, 3:32 p.m. |
OK |
MS C++ 2017 |
TESTS |
33 |
31 |
2457600 |
|
2400 |
71803807 |
pajenegod |
E |
Feb. 24, 2020, 4:12 p.m. |
OK |
PyPy 2 |
TESTS |
33 |
155 |
716800 |
|
2400 |
71807003 |
SPD_9X2 |
E |
Feb. 24, 2020, 4:25 p.m. |
OK |
PyPy 3 |
TESTS |
33 |
155 |
1945600 |
|
2400 |
71813377 |
Soapen |
E |
Feb. 24, 2020, 5:16 p.m. |
OK |
PyPy 3 |
TESTS |
33 |
155 |
2662400 |
|
2400 |
71800643 |
titia |
E |
Feb. 24, 2020, 3:59 p.m. |
OK |
PyPy 3 |
TESTS |
33 |
171 |
2457600 |
|
2400 |
71813000 |
tanon710 |
E |
Feb. 24, 2020, 5:12 p.m. |
OK |
PyPy 3 |
TESTS |
33 |
171 |
2662400 |
|
2400 |
71831384 |
thech0sen1 |
E |
Feb. 25, 2020, 3:03 a.m. |
OK |
PyPy 3 |
TESTS |
33 |
171 |
2764800 |
|
2400 |
71857348 |
pye |
E |
Feb. 25, 2020, 12:40 p.m. |
OK |
PyPy 3 |
TESTS |
33 |
249 |
9830400 |
|
2400 |
71844634 |
mkawa2 |
E |
Feb. 25, 2020, 8:45 a.m. |
OK |
Python 3 |
TESTS |
33 |
124 |
512000 |
|
2400 |
remove filters
Back to search problems