Codeforces Round 1081 (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
2192 Codeforces Round 1081 (Div. 2) FINISHED False 7200 4721123 Feb. 21, 2026, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 2002 ) E Swap to Rearrange PROGRAMMING constructive algorithms dfs and similar graph matchings graphs greedy strings

You are given (2) arrays, (a) and (b), both of length (n). You can perform the following operation: Choose an index (i) ((1 \le i \le n)) and swap (a_i) with (b_i). You can perform the operation any number of times (possibly zero), but each index can be chosen by at most one operation. Your task is to make (a) a rearrangement of (b) after all operations, or state that it is impossible. You do not have to minimize the number of 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^6)). The second line of each test case contains (n) integers (a_1,a_2,\ldots,a_n) ((1 \leq a_i \leq n)). The third line of each test case contains (n) integers (b_1,b_2,\ldots,b_n) ((1 \leq b_i \leq n)). It is guaranteed that the sum of (n) over all test cases does not exceed (10^6). For each test case, output (-1) if it is impossible to make (a) a rearrangement of (b). Otherwise, output two lines in the following format: In the first line, print the number of operations (s) ((0 \leq s \leq n)). In the second line of each test case, print (s) numbers – the indices you select in each operation in order. You should guarantee that each index is chosen at most once. If there are multiple possible answers, you many output any. In the first test case, the operations performed are swap((a_2, b_2)) and swap((a_4,b_4)), which will make (a = 1,2,3,4) and (b = 2,1,4,3). Now it is possible to achieve (a) by rearranging the elements of (b). In the second test case, it can be shown that no matter what operations we do, we cannot make (a) a rearrangement of (b).

Tutorials

Codeforces Round 1081 (Div. 2) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
363894588 -firefly- E Feb. 21, 2026, 4:12 p.m. OK C# 13 TESTS 27 1375 179712000
363895728 Lakibaja E Feb. 21, 2026, 4:15 p.m. OK C++17 (GCC 7-32) TESTS 27 703 55193600
363907014 CrossFire1 E Feb. 21, 2026, 5:20 p.m. OK C++17 (GCC 7-32) TESTS 27 718 50073600
363899970 Gypsies E Feb. 21, 2026, 4:26 p.m. OK C++17 (GCC 7-32) TESTS 27 734 49868800
363894039 KANG_MyeongSeok E Feb. 21, 2026, 4:11 p.m. OK C++17 (GCC 7-32) TESTS 27 750 57241600
363908390 W_Franklin E Feb. 21, 2026, 5:31 p.m. OK C++17 (GCC 7-32) TESTS 27 765 73420800
363946276 Z3k7223 E Feb. 22, 2026, 2:40 a.m. OK C++17 (GCC 7-32) TESTS 28 781 96358400
363893729 Teymur1 E Feb. 21, 2026, 4:10 p.m. OK C++17 (GCC 7-32) TESTS 27 812 61235200
363894778 xuan_never E Feb. 21, 2026, 4:13 p.m. OK C++17 (GCC 7-32) TESTS 27 812 104345600
363946957 xuan_never E Feb. 22, 2026, 3 a.m. OK C++17 (GCC 7-32) TESTS 28 828 133734400
363949800 lyc1001 E Feb. 22, 2026, 4:03 a.m. OK C++17 (GCC 7-32) TESTS 28 875 133324800
363900305 oliver326 E Feb. 21, 2026, 4:27 p.m. OK C++20 (GCC 13-64) TESTS 27 640 176435200
363897879 UKE2006 E Feb. 21, 2026, 4:20 p.m. OK C++20 (GCC 13-64) TESTS 27 718 179507200
363956828 syh-up E Feb. 22, 2026, 5:58 a.m. OK C++20 (GCC 13-64) TESTS 28 765 54579200
363895085 imaiwluv E Feb. 21, 2026, 4:13 p.m. OK C++20 (GCC 13-64) TESTS 27 781 53657600
363893485 t98slider E Feb. 21, 2026, 4:10 p.m. OK C++20 (GCC 13-64) TESTS 27 781 75059200
363898506 cosenza E Feb. 21, 2026, 4:22 p.m. OK C++20 (GCC 13-64) TESTS 27 796 49561600
363894304 Ynoel E Feb. 21, 2026, 4:12 p.m. OK C++20 (GCC 13-64) TESTS 27 1000 154009600
363896418 legendcn E Feb. 21, 2026, 4:17 p.m. OK C++20 (GCC 13-64) TESTS 27 1015 105267200
363939992 Tenshi E Feb. 21, 2026, 11:55 p.m. OK C++20 (GCC 13-64) TESTS 28 1109 118579200
363938166 julia_08 E Feb. 21, 2026, 11:09 p.m. OK C++20 (GCC 13-64) TESTS 28 1125 156262400
363903458 bashan182 E Feb. 21, 2026, 4:33 p.m. OK C++23 (GCC 14-64, msys2) TESTS 27 687 62361600
363951486 lizeeee E Feb. 22, 2026, 4:33 a.m. OK C++23 (GCC 14-64, msys2) TESTS 28 718 197939200
363907446 resolve100 E Feb. 21, 2026, 5:23 p.m. OK C++23 (GCC 14-64, msys2) TESTS 27 875 53350400
363897932 Lntano265 E Feb. 21, 2026, 4:21 p.m. OK C++23 (GCC 14-64, msys2) TESTS 27 921 56627200
363901118 Ginge E Feb. 21, 2026, 4:28 p.m. OK C++23 (GCC 14-64, msys2) TESTS 27 953 53350400
363899891 rrop1078 E Feb. 21, 2026, 4:25 p.m. OK C++23 (GCC 14-64, msys2) TESTS 27 984 62054400
363896692 __Maksik__ E Feb. 21, 2026, 4:18 p.m. OK C++23 (GCC 14-64, msys2) TESTS 27 1015 85811200
363908683 Left0807 E Feb. 21, 2026, 5:33 p.m. OK C++23 (GCC 14-64, msys2) TESTS 27 1078 71475200
363943687 rabinkarp E Feb. 22, 2026, 1:39 a.m. OK C++23 (GCC 14-64, msys2) TESTS 28 1078 127180800
363893771 wangyuzhe E Feb. 21, 2026, 4:10 p.m. OK C++23 (GCC 14-64, msys2) TESTS 27 1093 75571200
363902678 Ankesh_amar E Feb. 21, 2026, 4:32 p.m. OK Java 21 TESTS 27 1078 105881600
363894805 aha E Feb. 21, 2026, 4:13 p.m. OK Java 21 TESTS 27 1140 45363200
363903943 Power_Rangers_ E Feb. 21, 2026, 4:34 p.m. OK Java 21 TESTS 27 1703 143155200
363897314 Mahesh_021 E Feb. 21, 2026, 4:19 p.m. OK Java 21 TESTS 27 2609 136089600
363898936 daniel.glabai E Feb. 21, 2026, 4:23 p.m. OK Java 21 TESTS 27 2859 231219200
363937773 tarun_op E Feb. 21, 2026, 11 p.m. OK Java 21 TESTS 28 3484 295526400
363903612 sry112 E Feb. 21, 2026, 4:34 p.m. OK Java 21 TESTS 27 3765 54169600
363957350 kevin_0911 E Feb. 22, 2026, 6:05 a.m. OK Java 8 TESTS 28 2921 327987200
363896979 tanmaygarg021103 E Feb. 21, 2026, 4:18 p.m. OK Java 8 TESTS 27 3250 31948800
363895827 abhi... E Feb. 21, 2026, 4:15 p.m. OK Java 8 TESTS 27 4812 182374400
363956028 kevin_0911 E Feb. 22, 2026, 5:48 a.m. OK Java 8 TESTS 28 4875 446361600
363903042 tryingDream E Feb. 21, 2026, 4:33 p.m. OK Kotlin 2.2 TESTS 27 734 91340800
363943533 Meguhine E Feb. 22, 2026, 1:34 a.m. OK PyPy 3-64 TESTS 28 1484 205516800
363943653 Meguhine E Feb. 22, 2026, 1:38 a.m. OK PyPy 3-64 TESTS 28 1515 205209600
363943636 Meguhine E Feb. 22, 2026, 1:38 a.m. OK PyPy 3-64 TESTS 28 1562 202240000
363943222 Meguhine E Feb. 22, 2026, 1:26 a.m. OK PyPy 3-64 TESTS 28 1578 228249600
363943288 Meguhine E Feb. 22, 2026, 1:27 a.m. OK PyPy 3-64 TESTS 28 1640 214835200
363898587 hugoback01 E Feb. 21, 2026, 4:22 p.m. OK PyPy 3-64 TESTS 27 2953 252416000
363907066 ardeelia E Feb. 21, 2026, 5:21 p.m. OK PyPy 3-64 TESTS 27 3515 415232000
363907535 krism E Feb. 21, 2026, 5:23 p.m. OK PyPy 3-64 TESTS 27 3781 372224000
363912466 DeadMan69 E Feb. 21, 2026, 6 p.m. OK PyPy 3-64 TESTS 27 3859 401920000
363916208 ThatOnePythonUser E Feb. 21, 2026, 6:29 p.m. OK PyPy 3-64 TESTS 27 4312 416256000
363914333 Jimanbanashi E Feb. 21, 2026, 6:14 p.m. OK Python 2 TESTS 27 4078 114073600
363901708 pathaksneha9322 E Feb. 21, 2026, 4:30 p.m. OK Python 3 TESTS 27 4625 521318400
363903646 mertyilmaz E Feb. 21, 2026, 4:34 p.m. OK Rust 2024 TESTS 27 2187 524595200
363894210 DanielAnker E Feb. 21, 2026, 4:11 p.m. OK Rust 2024 TESTS 27 2718 291123200

remove filters

Back to search problems