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'In the end of the day, Anna needs to turn off the lights in the office. There are n lights and n light switches, but their operation scheme is really strange. The switch i changes the state of light i , but it also changes the state of some other light a_i (change the state means that if the light was on, it goes off and vice versa). Help Anna to turn all the lights off using minimal number of switches, or say it is impossible. The first line of input contains a single integer t ( 1 <= t <= 10^4 ) -- the number of test cases. Descriptions of test cases follow. The first line of each test case contains the integer n ( 2 <= n <= 10^5 ) -- the number of lights. The second line of each test case contains the string of n characters, the initial state of the lights. Character "0" means that the corresponding light is off, and "1" means that it is on. The third line of each test case contains n integers a_i ( 1 <= a_i <= n , a_i neq i ) -- the switch i changes the states of light i and light a_i . It is guaranteed that sum of n over all test cases does not exceed 2 cdot 10^5 For each test case output the integer k , the minimal number of switches to use, then in the separate line output the list of k switches. If it is impossible to turn off all the lights, output single integer -1 . '... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
235991915 |
wsday |
G |
Dec. 6, 2023, 3:41 a.m. |
OK |
GNU C++14 |
TESTS |
31 |
77 |
2560000 |
|
|
235973181 |
Joacru |
G |
Dec. 5, 2023, 8:34 p.m. |
OK |
GNU C++14 |
TESTS |
31 |
78 |
3276800 |
|
|
235948348 |
Cu_OH_2 |
G |
Dec. 5, 2023, 4:56 p.m. |
OK |
GNU C++14 |
TESTS |
31 |
93 |
2764800 |
|
|
235983752 |
MegalovaniaJ |
G |
Dec. 6, 2023, 1:07 a.m. |
OK |
GNU C++14 |
TESTS |
31 |
93 |
3276800 |
|
|
235952895 |
CoachDanke |
G |
Dec. 5, 2023, 5:11 p.m. |
OK |
GNU C++14 |
TESTS |
31 |
109 |
11980800 |
|
|
235965488 |
sword1e1 |
G |
Dec. 5, 2023, 6:58 p.m. |
OK |
GNU C++17 |
TESTS |
31 |
62 |
1843200 |
|
|
235986740 |
fsl123 |
G |
Dec. 6, 2023, 2:15 a.m. |
OK |
GNU C++17 |
TESTS |
31 |
62 |
2969600 |
|
|
235989985 |
Tri17 |
G |
Dec. 6, 2023, 3:08 a.m. |
OK |
GNU C++17 |
TESTS |
31 |
77 |
1843200 |
|
|
235943993 |
Guslix |
G |
Dec. 5, 2023, 4:46 p.m. |
OK |
GNU C++17 |
TESTS |
31 |
77 |
2355200 |
|
|
235975112 |
FzArK |
G |
Dec. 5, 2023, 9:06 p.m. |
OK |
GNU C++17 |
TESTS |
31 |
77 |
7065600 |
|
|
235990619 |
otoshigo |
G |
Dec. 6, 2023, 3:18 a.m. |
OK |
GNU C++17 |
TESTS |
31 |
78 |
1945600 |
|
|
235944172 |
liuyz11 |
G |
Dec. 5, 2023, 4:47 p.m. |
OK |
GNU C++17 |
TESTS |
31 |
78 |
2457600 |
|
|
235994847 |
Xiaobaibubai |
G |
Dec. 6, 2023, 4:33 a.m. |
OK |
GNU C++17 |
TESTS |
31 |
78 |
3072000 |
|
|
235958122 |
lddlinan |
G |
Dec. 5, 2023, 5:47 p.m. |
OK |
GNU C++17 |
TESTS |
31 |
78 |
4915200 |
|
|
235946494 |
Ste |
G |
Dec. 5, 2023, 4:52 p.m. |
OK |
GNU C++17 |
TESTS |
31 |
93 |
1843200 |
|
|
235991248 |
FlowRays |
G |
Dec. 6, 2023, 3:30 a.m. |
OK |
GNU C++17 (64) |
TESTS |
31 |
31 |
4710400 |
|
|
235990864 |
FlowRays |
G |
Dec. 6, 2023, 3:23 a.m. |
OK |
GNU C++17 (64) |
TESTS |
31 |
31 |
4710400 |
|
|
235989308 |
wsyear |
G |
Dec. 6, 2023, 2:58 a.m. |
OK |
GNU C++17 (64) |
TESTS |
31 |
46 |
3072000 |
|
|
235962286 |
bestzzz |
G |
Dec. 5, 2023, 6:25 p.m. |
OK |
GNU C++17 (64) |
TESTS |
31 |
46 |
4403200 |
|
|
235990466 |
FlowRays |
G |
Dec. 6, 2023, 3:16 a.m. |
OK |
GNU C++17 (64) |
TESTS |
31 |
46 |
6758400 |
|
|
235960163 |
bestzzz |
G |
Dec. 5, 2023, 6:05 p.m. |
OK |
GNU C++17 (64) |
TESTS |
31 |
61 |
1945600 |
|
|
235956813 |
jican000 |
G |
Dec. 5, 2023, 5:37 p.m. |
OK |
GNU C++17 (64) |
TESTS |
31 |
61 |
2150400 |
|
|
235987670 |
Mellow_Yellow |
G |
Dec. 6, 2023, 2:34 a.m. |
OK |
GNU C++17 (64) |
TESTS |
31 |
62 |
1945600 |
|
|
235989229 |
LXH-cat |
G |
Dec. 6, 2023, 2:56 a.m. |
OK |
GNU C++17 (64) |
TESTS |
31 |
62 |
2355200 |
|
|
235991822 |
Einstein1234 |
G |
Dec. 6, 2023, 3:40 a.m. |
OK |
GNU C++17 (64) |
TESTS |
31 |
62 |
3686400 |
|
|
235989282 |
cmk666 |
G |
Dec. 6, 2023, 2:57 a.m. |
OK |
GNU C++20 (64) |
TESTS |
31 |
31 |
3379200 |
|
|
235987429 |
fanyi |
G |
Dec. 6, 2023, 2:29 a.m. |
OK |
GNU C++20 (64) |
TESTS |
31 |
46 |
1638400 |
|
|
235946461 |
Pervushev |
G |
Dec. 5, 2023, 4:52 p.m. |
OK |
GNU C++20 (64) |
TESTS |
31 |
46 |
1843200 |
|
|
235996171 |
Ycfhnnd |
G |
Dec. 6, 2023, 4:53 a.m. |
OK |
GNU C++20 (64) |
TESTS |
31 |
46 |
1945600 |
|
|
235995020 |
Fiatiustitia |
G |
Dec. 6, 2023, 4:36 a.m. |
OK |
GNU C++20 (64) |
TESTS |
31 |
46 |
1945600 |
|
|
235988438 |
ukuk |
G |
Dec. 6, 2023, 2:45 a.m. |
OK |
GNU C++20 (64) |
TESTS |
31 |
46 |
1945600 |
|
|
235977632 |
menezesd2 |
G |
Dec. 5, 2023, 9:57 p.m. |
OK |
GNU C++20 (64) |
TESTS |
31 |
46 |
1945600 |
|
|
235972914 |
greencis |
G |
Dec. 5, 2023, 8:31 p.m. |
OK |
GNU C++20 (64) |
TESTS |
31 |
46 |
1945600 |
|
|
235972380 |
liangjiahui11 |
G |
Dec. 5, 2023, 8:23 p.m. |
OK |
GNU C++20 (64) |
TESTS |
31 |
46 |
1945600 |
|
|
235971589 |
liangjiahui11 |
G |
Dec. 5, 2023, 8:13 p.m. |
OK |
GNU C++20 (64) |
TESTS |
31 |
46 |
1945600 |
|
|
235985044 |
0x3F |
G |
Dec. 6, 2023, 1:40 a.m. |
OK |
Go |
TESTS |
31 |
109 |
7577600 |
|
|
235985093 |
0x3F |
G |
Dec. 6, 2023, 1:41 a.m. |
OK |
Go |
TESTS |
31 |
139 |
7577600 |
|
|
235975688 |
fpeterfalvi |
G |
Dec. 5, 2023, 9:18 p.m. |
OK |
Java 11 |
TESTS |
31 |
717 |
31846400 |
|
|
235989617 |
28leoleo28 |
G |
Dec. 6, 2023, 3:03 a.m. |
OK |
Java 17 |
TESTS |
31 |
670 |
33894400 |
|
|
235989987 |
28leoleo28 |
G |
Dec. 6, 2023, 3:08 a.m. |
OK |
Java 17 |
TESTS |
31 |
670 |
34406400 |
|
|
235980386 |
mcrash12 |
G |
Dec. 5, 2023, 11:20 p.m. |
OK |
Java 21 |
TESTS |
31 |
608 |
12390400 |
|
|
235980453 |
mcrash12 |
G |
Dec. 5, 2023, 11:22 p.m. |
OK |
Java 21 |
TESTS |
31 |
639 |
13209600 |
|
|
235998313 |
1091857051 |
G |
Dec. 6, 2023, 5:21 a.m. |
OK |
Java 8 |
TESTS |
31 |
186 |
409600 |
|
|
235951729 |
DeadlyPillow |
G |
Dec. 5, 2023, 5:06 p.m. |
OK |
Kotlin 1.7 |
TESTS |
31 |
1746 |
128614400 |
|
|
235991653 |
Quick-One |
G |
Dec. 6, 2023, 3:37 a.m. |
OK |
PyPy 3 |
TESTS |
31 |
842 |
52121600 |
|
|
235985088 |
SoleProprietor |
G |
Dec. 6, 2023, 1:41 a.m. |
OK |
PyPy 3-64 |
TESTS |
31 |
217 |
19148800 |
|
|
235953862 |
blue_ice_yj |
G |
Dec. 5, 2023, 5:17 p.m. |
OK |
PyPy 3-64 |
TESTS |
31 |
233 |
31846400 |
|
|
235955149 |
blue_ice_yj |
G |
Dec. 5, 2023, 5:25 p.m. |
OK |
PyPy 3-64 |
TESTS |
31 |
295 |
31232000 |
|
|
235982365 |
liupengsay |
G |
Dec. 6, 2023, 12:27 a.m. |
OK |
PyPy 3-64 |
TESTS |
31 |
343 |
23040000 |
|
|
235991493 |
kavorka |
G |
Dec. 6, 2023, 3:34 a.m. |
OK |
PyPy 3-64 |
TESTS |
31 |
374 |
63795200 |
|
|
235953163 |
Lammert0907 |
G |
Dec. 5, 2023, 5:13 p.m. |
OK |
PyPy 3-64 |
TESTS |
31 |
498 |
25190400 |
|
|
235970213 |
nehan_der_thal |
G |
Dec. 5, 2023, 7:54 p.m. |
OK |
PyPy 3-64 |
TESTS |
31 |
498 |
36864000 |
|
|
235986544 |
YMSeah |
G |
Dec. 6, 2023, 2:11 a.m. |
OK |
PyPy 3-64 |
TESTS |
31 |
716 |
76595200 |
|
|
235992135 |
Quick-One |
G |
Dec. 6, 2023, 3:46 a.m. |
OK |
PyPy 3-64 |
TESTS |
31 |
717 |
71168000 |
|
|
235991667 |
Quick-One |
G |
Dec. 6, 2023, 3:37 a.m. |
OK |
PyPy 3-64 |
TESTS |
31 |
795 |
79564800 |
|
|
235954982 |
zhdanovich |
G |
Dec. 5, 2023, 5:24 p.m. |
OK |
Python 3 |
TESTS |
31 |
296 |
21196800 |
|
|
235948011 |
MarshallRNH2 |
G |
Dec. 5, 2023, 4:55 p.m. |
OK |
Python 3 |
TESTS |
31 |
670 |
38604800 |
|
|
235955152 |
robostac |
G |
Dec. 5, 2023, 5:25 p.m. |
OK |
Rust 2021 |
TESTS |
31 |
124 |
17305600 |
|
|
235954518 |
robostac |
G |
Dec. 5, 2023, 5:21 p.m. |
OK |
Rust 2021 |
TESTS |
31 |
139 |
17305600 |
|
|
235955227 |
robostac |
G |
Dec. 5, 2023, 5:25 p.m. |
OK |
Rust 2021 |
TESTS |
31 |
140 |
17305600 |
|
|
remove filters
Back to search problems