Codeforces Round 1091 (Div. 2) and CodeCraft 26

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
2217 Codeforces Round 1091 (Div. 2) and CodeCraft 26 FINISHED False 8100 3165930 April 7, 2026, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 371 ) G Down the Pivot PROGRAMMING combinatorics trees

Consider binary trees where each node has at most two children, and each node is labeled with either (0) or (1). In one operation, you can flip all the labels on any simple path that passes through the root. Flipping a label means changing (0) to (1) and (1) to (0). Note that a path of length (1) containing only the root is also allowed. The cost of such a binary tree is defined as the minimum number of operations required to make all labels in the tree equal to (0). Given two integers (n) and (k), count the number of distinct labeled binary trees with exactly (n) nodes and cost exactly (k). Since the answer can be very large, output it modulo (10^9 + 7). Two binary trees are considered distinct if they have different structures, or if they have the same structure but differ in at least one node's label. 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 only line of each test case contains two integers (n) and (k) ((1 \le n \le 10^6), (0 \le k \le n)). It is guaranteed that the sum of (n) over all test cases does not exceed (10^6). For each test case, output a single integer on a new line — the number of labeled binary trees with (n) nodes and cost (k), modulo (10^9+7). In the first test case, we have (n=2) and (k=0). There are two possible trees—a root with a left child and a root with a right child. Since we need a cost of (0), all nodes must be labeled (0). Thus, the answer is (2). In the second test case, (n=2) and (k=1). There are (4) such trees. The valid labeled trees are shown in the figure below: In the third test case, (n=1) and (k=1). There is only one tree—a single root node with label (1). Thus, the answer is (1).

Tutorials

Tutorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
370184229 nullbrain_ G April 7, 2026, 4:49 p.m. OK C# 13 TESTS 17 140 30617600
370182276 nulleddzb G April 7, 2026, 4:43 p.m. OK C++17 (GCC 7-32) TESTS 17 156 12185600
370213224 Can_I_Know_Who_Im_I G April 8, 2026, 1:25 a.m. OK C++17 (GCC 7-32) TESTS 17 171 52224000
370171040 Hurricane G April 7, 2026, 4:06 p.m. OK C++17 (GCC 7-32) TESTS 17 187 28160000
370171043 independent G April 7, 2026, 4:06 p.m. OK C++17 (GCC 7-32) TESTS 17 218 44134400
370182297 waris12 G April 7, 2026, 4:43 p.m. OK C++17 (GCC 7-32) TESTS 17 218 44236800
370173509 ntlinh2110 G April 7, 2026, 4:13 p.m. OK C++17 (GCC 7-32) TESTS 17 234 44236800
370171956 khanhphan662007 G April 7, 2026, 4:08 p.m. OK C++17 (GCC 7-32) TESTS 17 234 48128000
370200893 pacmanbh123 G April 7, 2026, 7:54 p.m. OK C++17 (GCC 7-32) TESTS 17 234 68198400
370220306 Hazrat-Fatema G April 8, 2026, 3:59 a.m. OK C++17 (GCC 7-32) TESTS 17 281 32153600
370174522 rlakkh G April 7, 2026, 4:16 p.m. OK C++17 (GCC 7-32) TESTS 17 312 20172800
370175155 ChatGPT4.0 G April 7, 2026, 4:18 p.m. OK C++20 (GCC 13-64) TESTS 17 62 32153600
370215773 hzs090912 G April 8, 2026, 2:31 a.m. OK C++20 (GCC 13-64) TESTS 17 78 48128000
370220507 9s600km G April 8, 2026, 4:02 a.m. OK C++20 (GCC 13-64) TESTS 17 93 60313600
370205582 cooldude93094 G April 7, 2026, 9:21 p.m. OK C++20 (GCC 13-64) TESTS 17 93 64102400
370180370 AA-2007 G April 7, 2026, 4:36 p.m. OK C++20 (GCC 13-64) TESTS 17 93 67276800
370192946 noya2 G April 7, 2026, 6:18 p.m. OK C++20 (GCC 13-64) TESTS 17 109 35123200
370173320 woyebuzhidaowoshishui G April 7, 2026, 4:12 p.m. OK C++20 (GCC 13-64) TESTS 17 109 48128000
370179076 aaa_Pigeon2 G April 7, 2026, 4:32 p.m. OK C++20 (GCC 13-64) TESTS 17 109 56115200
370211159 Adzkoyyy G April 8, 2026, 12:38 a.m. OK C++20 (GCC 13-64) TESTS 17 109 72192000
370212858 srikkanthr G April 8, 2026, 1:15 a.m. OK C++20 (GCC 13-64) TESTS 17 109 80179200
370222587 maithehung123 G April 8, 2026, 4:38 a.m. OK C++23 (GCC 14-64, msys2) TESTS 17 78 44441600
370211547 go_tidy G April 8, 2026, 12:52 a.m. OK C++23 (GCC 14-64, msys2) TESTS 17 93 12288000
370183797 Paroxetine G April 7, 2026, 4:48 p.m. OK C++23 (GCC 14-64, msys2) TESTS 17 93 13619200
370206817 StevenKnight G April 7, 2026, 9:51 p.m. OK C++23 (GCC 14-64, msys2) TESTS 17 93 48128000
370176739 j_zarcoo G April 7, 2026, 4:24 p.m. OK C++23 (GCC 14-64, msys2) TESTS 17 93 48128000
370177212 pippo_9316 G April 7, 2026, 4:25 p.m. OK C++23 (GCC 14-64, msys2) TESTS 17 93 52326400
370184547 ayushkumargupta2908 G April 7, 2026, 4:49 p.m. OK C++23 (GCC 14-64, msys2) TESTS 17 93 52428800
370201559 optimumpride290347 G April 7, 2026, 8:05 p.m. OK C++23 (GCC 14-64, msys2) TESTS 17 93 60416000
370180901 TrinhDuongYang G April 7, 2026, 4:38 p.m. OK C++23 (GCC 14-64, msys2) TESTS 17 93 60416000
370177964 omayushmishra G April 7, 2026, 4:28 p.m. OK C++23 (GCC 14-64, msys2) TESTS 17 109 24064000
370172087 Divya04P G April 7, 2026, 4:09 p.m. OK Java 21 TESTS 17 453 74035200
370183109 bitplease_ G April 7, 2026, 4:46 p.m. OK Node.js TESTS 17 531 26112000
370176005 ashusinghcse G April 7, 2026, 4:21 p.m. OK PyPy 3-64 TESTS 17 312 105164800
370179786 harurun4635 G April 7, 2026, 4:34 p.m. OK PyPy 3-64 TESTS 17 1515 78848000
370184109 trycatchcry G April 7, 2026, 4:48 p.m. OK Rust 2024 TESTS 17 125 55910400

remove filters

Back to search problems