Codeforces Global Round 31 (Div. 1 + 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
2180 Codeforces Global Round 31 (Div. 1 + Div. 2) FINISHED False 9000 10250722 Dec. 19, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 6386 ) C XOR-factorization PROGRAMMING bitmasks constructive algorithms dp greedy number theory

Ostad thinks that the usual way of factoring numbers is too mathematical, so he invented a new notion called XOR-factorization , which is more computer-science-like. For a given integer (n), a sequence of integers (a_1, a_2, \ldots, a_k) with (0 \le a_i \le n) for all (i) is called a XOR-factorization of (n) if and only if () a_1 \oplus a_2 \oplus \cdots \oplus a_k = n, () where (\oplus) denotes the bitwise XOR operation . You are given integers (n) and (k). Find a XOR-factorization (a_1, a_2, \ldots, a_k) of (n) that maximizes the sum (a_1 + a_2 + \cdots + a_k). It can be proven that under the problem conditions, a XOR-factorization always exists. 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. Each of the next (t) lines contains two integers (n) and (k) ((1 \le n \le 10^9), (1 \le k \le 10^5)). It is guaranteed that the sum of (k) over all test cases does not exceed (10^5). For each test case, output (k) integers (a_1, a_2, \ldots, a_k) such that (0 \le a_i \le n). We can show that an answer always exists. If there are multiple valid answers, you may print any of them in any order. In the first test case, we can factor (5) as (1 \oplus 4 \oplus 5 \oplus 5) with a sum of (15), and it can be shown that no other XOR-factorization has a higher sum. In the second test case, we can factor (4) as (4 \oplus 4 \oplus 4) with a sum of (12), which is trivially the maximum possible.

Tutorials

Codeforces Global Round 31

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
354254538 coderkrishna11 C Dec. 20, 2025, 3:33 a.m. OK C++17 (GCC 7-32) TESTS 11 31 102400
354254117 wangtianze C Dec. 20, 2025, 3:25 a.m. OK C++17 (GCC 7-32) TESTS 11 31 512000
354228292 atharva_sagane_17 C Dec. 19, 2025, 6:36 p.m. OK C++17 (GCC 7-32) TESTS 10 31 4096000
354232169 21cs02001 C Dec. 19, 2025, 7:17 p.m. OK C++17 (GCC 7-32) TESTS 10 31 4198400
354264680 ajay018 C Dec. 20, 2025, 5:46 a.m. OK C++17 (GCC 7-32) TESTS 11 46 0
354263458 bhabluv C Dec. 20, 2025, 5:34 a.m. OK C++17 (GCC 7-32) TESTS 11 46 0
354261714 vivekanandpdy732 C Dec. 20, 2025, 5:15 a.m. OK C++17 (GCC 7-32) TESTS 11 46 0
354246338 nine11 C Dec. 20, 2025, 12:02 a.m. OK C++17 (GCC 7-32) TESTS 10 46 0
354232234 Bvenkatanath14 C Dec. 19, 2025, 7:18 p.m. OK C++17 (GCC 7-32) TESTS 10 46 0
354231903 yuugureyuu C Dec. 19, 2025, 7:14 p.m. OK C++17 (GCC 7-32) TESTS 10 46 0
354260961 YashK2803 C Dec. 20, 2025, 5:05 a.m. OK C++20 (GCC 13-64) TESTS 11 31 0
354258882 Apteryxx C Dec. 20, 2025, 4:39 a.m. OK C++20 (GCC 13-64) TESTS 11 31 0
354251422 Dave233 C Dec. 20, 2025, 2:31 a.m. OK C++20 (GCC 13-64) TESTS 11 31 0
354248811 arthurxu17 C Dec. 20, 2025, 1:25 a.m. OK C++20 (GCC 13-64) TESTS 10 31 0
354245811 _Manual_ C Dec. 19, 2025, 11:41 p.m. OK C++20 (GCC 13-64) TESTS 10 31 0
354240029 Victor_Ivis C Dec. 19, 2025, 9:07 p.m. OK C++20 (GCC 13-64) TESTS 10 31 0
354231490 nithish654 C Dec. 19, 2025, 7:10 p.m. OK C++20 (GCC 13-64) TESTS 10 31 0
354225597 maasir554 C Dec. 19, 2025, 6:13 p.m. OK C++20 (GCC 13-64) TESTS 10 31 0
354225586 ay186mnc C Dec. 19, 2025, 6:13 p.m. OK C++20 (GCC 13-64) TESTS 10 31 0
354266280 LuOH3_ C Dec. 20, 2025, 6:02 a.m. OK C++20 (GCC 13-64) TESTS 11 31 102400

remove filters

Back to search problems