Codeforces Round 1031 (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
2113 Codeforces Round 1031 (Div. 2) FINISHED False 7200 26427323 June 15, 2025, 9:05 a.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 948 ) F Two Arrays PROGRAMMING constructive algorithms dfs and similar graphs math

You are given two arrays (a) and (b) of length (n). You can perform the following operation an unlimited number of times: Choose an integer (i) from (1) to (n) and swap (a_i) and (b_i). Let (f(c)) be the number of distinct numbers in array (c). Find the maximum value of (f(a) + f(b)). Also, output the arrays (a) and (b) after performing all operations. 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 first line of each test case contains a single integer (n) ((1 \le n \le 10^5)) — the length of the arrays. The second line of each test case contains (n) integers (a_1, a_2, \ldots, a_n) ((1 \le a_i \le 2n)) — the elements of array (a). The third line of each test case contains (n) integers (b_1, b_2, \ldots, b_n) ((1 \le b_i \le 2n)) — the elements of array (b). It is guaranteed that the sum of (n) over all test cases does not exceed (10^5). For each test case, print a single integer in the first line — the maximum value of (f(a) + f(b)). In the second line, print (n) integers — the elements of array (a) after performing the operations. In the third line, print (n) integers — the elements of array (b) after performing the operations. In the first test case, after applying three operations with (i=2), (i=4), and (i=5), we obtain (a = 1, 3, 4, 5, 2) and (b = 1, 2, 3, 4, 4). After that, (f(a) + f(b) = 5 + 4 = 9). It can be shown that it is not possible to achieve a greater answer. In the second test case, after applying the operations: ()f(2, 3, 4, 2, 1, 5, 6) + f(1, 2, 3, 4, 5, 6, 5) = 6 + 6 = 12()

Tutorials

Codeforces Round #1031 Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
324518033 og.kostya F June 15, 2025, 11:46 a.m. OK C# 10 TESTS 68 421 67891200
324518098 og.kostya F June 15, 2025, 11:46 a.m. OK C# 13 TESTS 68 437 75776000
324584760 W_Franklin F June 16, 2025, 2:55 a.m. OK C++17 (GCC 7-32) TESTS 68 124 11980800
324587355 Skylerrrrr F June 16, 2025, 3:26 a.m. OK C++17 (GCC 7-32) TESTS 68 140 4812800
324528605 loip F June 15, 2025, 1:13 p.m. OK C++17 (GCC 7-32) TESTS 68 140 10342400
324525816 huangyuhan123456 F June 15, 2025, 12:43 p.m. OK C++17 (GCC 7-32) TESTS 68 156 19251200
324577504 ForwardStar F June 16, 2025, 12:01 a.m. OK C++17 (GCC 7-32) TESTS 68 156 27340800
324553943 2949767807qwer F June 15, 2025, 5 p.m. OK C++17 (GCC 7-32) TESTS 68 156 32460800
324583308 paulza F June 16, 2025, 2:30 a.m. OK C++17 (GCC 7-32) TESTS 68 171 9216000
324575621 Az3ar F June 15, 2025, 10:48 p.m. OK C++17 (GCC 7-32) TESTS 68 171 10035200
324535931 tfgs F June 15, 2025, 2:23 p.m. OK C++17 (GCC 7-32) TESTS 68 171 18636800
324542286 -adhd- F June 15, 2025, 3:17 p.m. OK C++17 (GCC 7-32) TESTS 68 186 9318400
324507750 fishcathu F June 15, 2025, 10:52 a.m. OK C++20 (GCC 13-64) TESTS 68 124 4096000
324524883 Joler_ F June 15, 2025, 12:34 p.m. OK C++20 (GCC 13-64) TESTS 68 140 12902400
324514722 Julyyyyyyy F June 15, 2025, 11:21 a.m. OK C++20 (GCC 13-64) TESTS 68 155 11878400
324580819 Gutark F June 16, 2025, 1:41 a.m. OK C++20 (GCC 13-64) TESTS 68 155 23040000
324572313 AYTDD F June 15, 2025, 9:09 p.m. OK C++20 (GCC 13-64) TESTS 68 156 35532800
324589063 Misty7 F June 16, 2025, 3:47 a.m. OK C++20 (GCC 13-64) TESTS 68 171 8704000
324512304 turska F June 15, 2025, 11:04 a.m. OK C++20 (GCC 13-64) TESTS 68 171 22118400
324590060 StayAlone F June 16, 2025, 3:58 a.m. OK C++20 (GCC 13-64) TESTS 68 186 22425600
324589319 StayAlone F June 16, 2025, 3:50 a.m. OK C++20 (GCC 13-64) TESTS 68 186 22425600
324590418 70dwdw F June 16, 2025, 4:02 a.m. OK C++20 (GCC 13-64) TESTS 68 187 24678400
324582972 AEM_YNxingkong F June 16, 2025, 2:24 a.m. OK C++23 (GCC 14-64, msys2) TESTS 68 124 33484800
324564861 jiangly F June 15, 2025, 6:56 p.m. OK C++23 (GCC 14-64, msys2) TESTS 68 140 8089600
324577004 VinnySJ F June 15, 2025, 11:40 p.m. OK C++23 (GCC 14-64, msys2) TESTS 68 140 14643200
324517012 ManyullynIngot F June 15, 2025, 11:36 a.m. OK C++23 (GCC 14-64, msys2) TESTS 68 140 26521600
324596719 scutsky F June 16, 2025, 5:29 a.m. OK C++23 (GCC 14-64, msys2) TESTS 68 140 28774400
324542693 Wael_Zaiback F June 15, 2025, 3:20 p.m. OK C++23 (GCC 14-64, msys2) TESTS 68 155 12492800
324585655 Marckess F June 16, 2025, 3:06 a.m. OK C++23 (GCC 14-64, msys2) TESTS 68 155 18432000
324530947 BLOBVISGOD F June 15, 2025, 1:35 p.m. OK C++23 (GCC 14-64, msys2) TESTS 68 156 8192000
324510149 handlethiscontestwell3 F June 15, 2025, 10:59 a.m. OK C++23 (GCC 14-64, msys2) TESTS 68 171 7884800
324511682 ckuhn222 F June 15, 2025, 11:02 a.m. OK C++23 (GCC 14-64, msys2) TESTS 68 171 8294400
324545755 golions F June 15, 2025, 3:45 p.m. OK Java 8 TESTS 68 640 93184000
324577229 golomb F June 15, 2025, 11:48 p.m. OK PyPy 3-64 TESTS 68 702 82227200
324568498 golomb F June 15, 2025, 7:53 p.m. OK PyPy 3-64 TESTS 68 765 85708800

remove filters

Back to search problems