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"William has an array of n integers a_1, a_2, ... , a_n . In one move he can swap two neighboring items. Two items a_i and a_j are considered neighboring if the condition |i - j| = 1 is satisfied. William wants you to calculate the minimal number of swaps he would need to perform to make it so that the array does not contain two neighboring items with the same parity. Each test contains multiple test cases. The first line contains the number of test cases t ( 1 <= t <= 10^4 ). Description of the test cases follows. The first line of each test case contains an integer n (1 <= n <= 10^5) which is the total number of items in William's array. The second line contains n integers a_1, a_2, ... , a_n (1 <= a_i <= 10^9) which are William's array. It is guaranteed that the sum of n over all test cases does not exceed 10^5 . For each test case output the minimal number of operations needed or -1 if it is impossible to get the array to a state when no neighboring numbers have the same parity. In the first test case the following sequence of operations would satisfy the requirements: In the second test case the array initially does not contain two neighboring items of the same parity. In the third test case the following sequence of operations would satisfy the requirements: In the fourth test case it is impossible to satisfy the requirements. In the fifth test case the following sequence of operations would satisfy the requirements: "... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
127416521 |
milan_s1 |
B |
Aug. 30, 2021, 4:44 a.m. |
OK |
GNU C11 |
TESTS |
18 |
61 |
4915200 |
|
1300 |
127381295 |
ja1467 |
B |
Aug. 29, 2021, 4:30 p.m. |
OK |
GNU C11 |
TESTS |
18 |
93 |
5427200 |
|
1300 |
127410392 |
pufanyi |
B |
Aug. 30, 2021, 2:15 a.m. |
OK |
GNU C++14 |
TESTS |
18 |
31 |
3993600 |
|
1300 |
127415045 |
ILoveNoodles666 |
B |
Aug. 30, 2021, 4:10 a.m. |
OK |
GNU C++14 |
TESTS |
18 |
31 |
4915200 |
|
1300 |
127383988 |
Noriel |
B |
Aug. 29, 2021, 4:40 p.m. |
OK |
GNU C++14 |
TESTS |
18 |
31 |
5222400 |
|
1300 |
127393984 |
obaydullahmhs |
B |
Aug. 29, 2021, 6:04 p.m. |
OK |
GNU C++14 |
TESTS |
18 |
31 |
5222400 |
|
1300 |
127385589 |
tokitsukaze |
B |
Aug. 29, 2021, 4:46 p.m. |
OK |
GNU C++14 |
TESTS |
18 |
31 |
6451200 |
|
1300 |
127418846 |
PavanK_025 |
B |
Aug. 30, 2021, 5:32 a.m. |
OK |
GNU C++14 |
TESTS |
18 |
31 |
11776000 |
|
1300 |
127391954 |
AlphaLeporis |
B |
Aug. 29, 2021, 5:04 p.m. |
OK |
GNU C++14 |
TESTS |
18 |
31 |
166400000 |
|
1300 |
127410302 |
luonanzzz |
B |
Aug. 30, 2021, 2:12 a.m. |
OK |
GNU C++14 |
TESTS |
18 |
46 |
3788800 |
|
1300 |
127395195 |
kiranchadhary |
B |
Aug. 29, 2021, 6:13 p.m. |
OK |
GNU C++14 |
TESTS |
18 |
46 |
3788800 |
|
1300 |
127413073 |
langminjie |
B |
Aug. 30, 2021, 3:26 a.m. |
OK |
GNU C++14 |
TESTS |
18 |
46 |
3788800 |
|
1300 |
127383665 |
pufanyi |
B |
Aug. 29, 2021, 4:39 p.m. |
OK |
GNU C++17 |
TESTS |
18 |
30 |
5017600 |
|
1300 |
127403742 |
ali404 |
B |
Aug. 29, 2021, 9:24 p.m. |
OK |
GNU C++17 |
TESTS |
18 |
31 |
4198400 |
|
1300 |
127409370 |
FeelFine |
B |
Aug. 30, 2021, 1:43 a.m. |
OK |
GNU C++17 |
TESTS |
18 |
31 |
4198400 |
|
1300 |
127399371 |
jatinkansal81 |
B |
Aug. 29, 2021, 7:21 p.m. |
OK |
GNU C++17 |
TESTS |
18 |
31 |
4505600 |
|
1300 |
127408651 |
DuncanKnight |
B |
Aug. 30, 2021, 1:17 a.m. |
OK |
GNU C++17 |
TESTS |
18 |
31 |
5632000 |
|
1300 |
127397947 |
anandankur |
B |
Aug. 29, 2021, 6:52 p.m. |
OK |
GNU C++17 |
TESTS |
18 |
31 |
6041600 |
|
1300 |
127391756 |
anandankur |
B |
Aug. 29, 2021, 5:04 p.m. |
OK |
GNU C++17 |
TESTS |
18 |
31 |
6041600 |
|
1300 |
127401140 |
_ForeRunner_ |
B |
Aug. 29, 2021, 8:04 p.m. |
OK |
GNU C++17 |
TESTS |
18 |
31 |
7270400 |
|
1300 |
127412266 |
zhihanii |
B |
Aug. 30, 2021, 3:05 a.m. |
OK |
GNU C++17 |
TESTS |
18 |
46 |
3788800 |
|
1300 |
127414150 |
lmhtat |
B |
Aug. 30, 2021, 3:51 a.m. |
OK |
GNU C++17 |
TESTS |
18 |
46 |
3788800 |
|
1300 |
127413052 |
uuku |
B |
Aug. 30, 2021, 3:25 a.m. |
OK |
GNU C++17 (64) |
TESTS |
18 |
30 |
8908800 |
|
1300 |
127379743 |
Jasiekstrz |
B |
Aug. 29, 2021, 4:25 p.m. |
OK |
GNU C++17 (64) |
TESTS |
18 |
31 |
4710400 |
|
1300 |
127407340 |
_Isaunoya_ |
B |
Aug. 30, 2021, 12:16 a.m. |
OK |
GNU C++17 (64) |
TESTS |
18 |
31 |
4915200 |
|
1300 |
127397243 |
jainmilind |
B |
Aug. 29, 2021, 6:40 p.m. |
OK |
GNU C++17 (64) |
TESTS |
18 |
31 |
5120000 |
|
1300 |
127403385 |
epsilon_573 |
B |
Aug. 29, 2021, 9:11 p.m. |
OK |
GNU C++17 (64) |
TESTS |
18 |
31 |
5120000 |
|
1300 |
127402733 |
Anish_aak |
B |
Aug. 29, 2021, 8:50 p.m. |
OK |
GNU C++17 (64) |
TESTS |
18 |
31 |
5120000 |
|
1300 |
127405319 |
MazenBatrawi |
B |
Aug. 29, 2021, 10:26 p.m. |
OK |
GNU C++17 (64) |
TESTS |
18 |
31 |
5120000 |
|
1300 |
127413527 |
Aman_Tiwari |
B |
Aug. 30, 2021, 3:37 a.m. |
OK |
GNU C++17 (64) |
TESTS |
18 |
31 |
5120000 |
|
1300 |
127395093 |
VPhg |
B |
Aug. 29, 2021, 6:12 p.m. |
OK |
GNU C++17 (64) |
TESTS |
18 |
31 |
5222400 |
|
1300 |
127411010 |
Richw818 |
B |
Aug. 30, 2021, 2:34 a.m. |
OK |
GNU C++17 (64) |
TESTS |
18 |
31 |
5222400 |
|
1300 |
127385253 |
gealbermorales |
B |
Aug. 29, 2021, 4:45 p.m. |
OK |
Go |
TESTS |
18 |
124 |
16076800 |
|
1300 |
127403185 |
_Body |
B |
Aug. 29, 2021, 9:04 p.m. |
OK |
Java 11 |
TESTS |
18 |
187 |
23961600 |
|
1300 |
127415699 |
dhruvil_8803 |
B |
Aug. 30, 2021, 4:26 a.m. |
OK |
Java 11 |
TESTS |
18 |
202 |
23756800 |
|
1300 |
127404817 |
adarsh_goku |
B |
Aug. 29, 2021, 10:03 p.m. |
OK |
Java 11 |
TESTS |
18 |
202 |
23859200 |
|
1300 |
127416652 |
mrlucent |
B |
Aug. 30, 2021, 4:47 a.m. |
OK |
Java 11 |
TESTS |
18 |
202 |
24166400 |
|
1300 |
127415855 |
Tharun0102 |
B |
Aug. 30, 2021, 4:30 a.m. |
OK |
Java 11 |
TESTS |
18 |
217 |
23756800 |
|
1300 |
127399530 |
Noureldin_Farag |
B |
Aug. 29, 2021, 7:24 p.m. |
OK |
Java 11 |
TESTS |
18 |
218 |
23859200 |
|
1300 |
127380466 |
tushar_patil |
B |
Aug. 29, 2021, 4:27 p.m. |
OK |
Java 11 |
TESTS |
18 |
218 |
24064000 |
|
1300 |
127385591 |
kartikpapney |
B |
Aug. 29, 2021, 4:46 p.m. |
OK |
Java 11 |
TESTS |
18 |
233 |
23859200 |
|
1300 |
127402636 |
tushar19280 |
B |
Aug. 29, 2021, 8:47 p.m. |
OK |
Java 11 |
TESTS |
18 |
233 |
24064000 |
|
1300 |
127417800 |
ak6494285 |
B |
Aug. 30, 2021, 5:11 a.m. |
OK |
Java 11 |
TESTS |
18 |
234 |
43929600 |
|
1300 |
127411500 |
wyxfwxh250821 |
B |
Aug. 30, 2021, 2:46 a.m. |
OK |
Java 8 |
TESTS |
18 |
124 |
20480000 |
|
1300 |
127399549 |
themadknight45 |
B |
Aug. 29, 2021, 7:25 p.m. |
OK |
Java 8 |
TESTS |
18 |
139 |
21708800 |
|
1300 |
127420458 |
fortune95 |
B |
Aug. 30, 2021, 6:01 a.m. |
OK |
Java 8 |
TESTS |
18 |
140 |
20480000 |
|
1300 |
127397726 |
omar_mohammed |
B |
Aug. 29, 2021, 6:48 p.m. |
OK |
Java 8 |
TESTS |
18 |
155 |
20582400 |
|
1300 |
127387440 |
Adi_7861 |
B |
Aug. 29, 2021, 4:52 p.m. |
OK |
Java 8 |
TESTS |
18 |
155 |
20889600 |
|
1300 |
127411639 |
jagdish1998 |
B |
Aug. 30, 2021, 2:49 a.m. |
OK |
Java 8 |
TESTS |
18 |
155 |
22118400 |
|
1300 |
127393998 |
amit_roy |
B |
Aug. 29, 2021, 6:04 p.m. |
OK |
Java 8 |
TESTS |
18 |
156 |
20582400 |
|
1300 |
127418543 |
pdk.abhishek |
B |
Aug. 30, 2021, 5:27 a.m. |
OK |
Java 8 |
TESTS |
18 |
156 |
22528000 |
|
1300 |
127414364 |
rakshith572 |
B |
Aug. 30, 2021, 3:55 a.m. |
OK |
Java 8 |
TESTS |
18 |
170 |
20889600 |
|
1300 |
127396628 |
Swapniltri |
B |
Aug. 29, 2021, 6:31 p.m. |
OK |
Java 8 |
TESTS |
18 |
170 |
21196800 |
|
1300 |
127386032 |
arvindf232 |
B |
Aug. 29, 2021, 4:47 p.m. |
OK |
Kotlin |
TESTS |
18 |
171 |
21606400 |
|
1300 |
127411788 |
_chaopaonansheng |
B |
Aug. 30, 2021, 2:52 a.m. |
OK |
MS C++ 2017 |
TESTS |
18 |
46 |
4096000 |
|
1300 |
127391823 |
P___ |
B |
Aug. 29, 2021, 5:04 p.m. |
OK |
MS C++ 2017 |
TESTS |
18 |
62 |
4915200 |
|
1300 |
127387171 |
YaMi506 |
B |
Aug. 29, 2021, 4:51 p.m. |
OK |
MS C++ 2017 |
TESTS |
18 |
108 |
4915200 |
|
1300 |
127411329 |
adasanvin12345 |
B |
Aug. 30, 2021, 2:42 a.m. |
OK |
MS C++ 2017 |
TESTS |
18 |
108 |
6246400 |
|
1300 |
127387329 |
milf__hunter |
B |
Aug. 29, 2021, 4:52 p.m. |
OK |
MS C++ 2017 |
TESTS |
18 |
109 |
5324800 |
|
1300 |
127390547 |
Ilyaiq300 |
B |
Aug. 29, 2021, 5:02 p.m. |
OK |
MS C++ 2017 |
TESTS |
18 |
124 |
4915200 |
|
1300 |
127382036 |
WUT_ZJL |
B |
Aug. 29, 2021, 4:33 p.m. |
OK |
MS C++ 2017 |
TESTS |
18 |
592 |
4505600 |
|
1300 |
127418512 |
thetansquared |
B |
Aug. 30, 2021, 5:26 a.m. |
OK |
.NET Core C# |
TESTS |
18 |
202 |
51404800 |
|
1300 |
127405922 |
guanghechen |
B |
Aug. 29, 2021, 10:56 p.m. |
OK |
Node.js |
TESTS |
18 |
170 |
43520000 |
|
1300 |
127386994 |
ankit_64 |
B |
Aug. 29, 2021, 4:51 p.m. |
OK |
PyPy 3 |
TESTS |
18 |
233 |
30720000 |
|
1300 |
127410590 |
priya9m1 |
B |
Aug. 30, 2021, 2:22 a.m. |
OK |
PyPy 3 |
TESTS |
18 |
233 |
31027200 |
|
1300 |
127388677 |
greengoose |
B |
Aug. 29, 2021, 4:56 p.m. |
OK |
PyPy 3 |
TESTS |
18 |
234 |
30720000 |
|
1300 |
127393881 |
vaibhav_india |
B |
Aug. 29, 2021, 6:04 p.m. |
OK |
PyPy 3 |
TESTS |
18 |
249 |
31436800 |
|
1300 |
127419981 |
__Broly__ |
B |
Aug. 30, 2021, 5:53 a.m. |
OK |
PyPy 3 |
TESTS |
18 |
249 |
32358400 |
|
1300 |
127404366 |
RANK1ZEN |
B |
Aug. 29, 2021, 9:47 p.m. |
OK |
PyPy 3 |
TESTS |
18 |
264 |
30515200 |
|
1300 |
127407768 |
mmooyyii |
B |
Aug. 30, 2021, 12:36 a.m. |
OK |
PyPy 3 |
TESTS |
18 |
264 |
31334400 |
|
1300 |
127395026 |
Bad_day_toCode |
B |
Aug. 29, 2021, 6:12 p.m. |
OK |
PyPy 3 |
TESTS |
18 |
264 |
31334400 |
|
1300 |
127398947 |
legend.ary_as |
B |
Aug. 29, 2021, 7:11 p.m. |
OK |
PyPy 3 |
TESTS |
18 |
264 |
32153600 |
|
1300 |
127399879 |
RANK1ZEN |
B |
Aug. 29, 2021, 7:32 p.m. |
OK |
PyPy 3 |
TESTS |
18 |
265 |
30617600 |
|
1300 |
127391481 |
nwi |
B |
Aug. 29, 2021, 5:04 p.m. |
OK |
Python 2 |
TESTS |
18 |
171 |
12288000 |
|
1300 |
127400968 |
elistark |
B |
Aug. 29, 2021, 7:59 p.m. |
OK |
Python 2 |
TESTS |
18 |
186 |
12492800 |
|
1300 |
127395928 |
2019287 |
B |
Aug. 29, 2021, 6:22 p.m. |
OK |
Python 3 |
TESTS |
18 |
170 |
15360000 |
|
1300 |
127416499 |
kaushik1877 |
B |
Aug. 30, 2021, 4:44 a.m. |
OK |
Python 3 |
TESTS |
18 |
171 |
14950400 |
|
1300 |
127396047 |
sh1194 |
B |
Aug. 29, 2021, 6:23 p.m. |
OK |
Python 3 |
TESTS |
18 |
171 |
14950400 |
|
1300 |
127419138 |
Up_there |
B |
Aug. 30, 2021, 5:38 a.m. |
OK |
Python 3 |
TESTS |
18 |
171 |
15155200 |
|
1300 |
127413516 |
saurabh3195 |
B |
Aug. 30, 2021, 3:37 a.m. |
OK |
Python 3 |
TESTS |
18 |
186 |
14950400 |
|
1300 |
127413300 |
puffc0rn |
B |
Aug. 30, 2021, 3:32 a.m. |
OK |
Python 3 |
TESTS |
18 |
186 |
15974400 |
|
1300 |
127400818 |
AlienKiller |
B |
Aug. 29, 2021, 7:55 p.m. |
OK |
Python 3 |
TESTS |
18 |
202 |
14131200 |
|
1300 |
127413791 |
Quan2202 |
B |
Aug. 30, 2021, 3:43 a.m. |
OK |
Python 3 |
TESTS |
18 |
202 |
14848000 |
|
1300 |
127419818 |
behindyou |
B |
Aug. 30, 2021, 5:50 a.m. |
OK |
Python 3 |
TESTS |
18 |
202 |
14950400 |
|
1300 |
127380353 |
navarog |
B |
Aug. 29, 2021, 4:27 p.m. |
OK |
Python 3 |
TESTS |
18 |
233 |
15155200 |
|
1300 |
127394379 |
IvanDyachenko |
B |
Aug. 29, 2021, 6:06 p.m. |
OK |
Scala |
TESTS |
18 |
701 |
45772800 |
|
1300 |
remove filters
Back to search problems