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'There are n armchairs, numbered from 1 to n from left to right. Some armchairs are occupied by people (at most one person per armchair), others are not. The number of occupied armchairs is not greater than frac{n}{2} . For some reason, you would like to tell people to move from their armchairs to some other ones. If the i -th armchair is occupied by someone and the j -th armchair is not, you can tell the person sitting in the i -th armchair to move to the j -th armchair. The time it takes a person to move from the i -th armchair to the j -th one is |i - j| minutes. You may perform this operation any number of times, but these operations must be done sequentially, i. xe2 x80 x89e. you cannot tell a person to move until the person you asked to move in the last operation has finished moving to their destination armchair. You want to achieve the following situation: every seat that was initially occupied must be free. What is the minimum time you need to do it? The first line contains one integer n ( 2 <= n <= 5000 ) -- the number of armchairs. The second line contains n integers a_1, a_2, ... , a_n ( 0 <= a_i <= 1 ). a_i = 1 means that the i -th armchair is initially occupied, a_i = 0 means that it is initially free. The number of occupied armchairs is at most frac{n}{2} . Print one integer -- the minimum number of minutes you have to spend to achieve the following situation: every seat that was initially occupied must be free. In the first test, you can perform the following sequence: In the second test, you can perform the following sequence: In the third test, no seat is occupied so your goal is achieved instantly. '... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
116413733 |
ruban |
D |
May 16, 2021, 2:50 p.m. |
OK |
Delphi |
TESTS |
51 |
296 |
532582400 |
|
|
116441427 |
holmane333 |
D |
May 17, 2021, 1:43 a.m. |
OK |
GNU C11 |
TESTS |
51 |
62 |
50483200 |
|
|
116397130 |
sgtlaugh |
D |
May 16, 2021, 11:36 a.m. |
OK |
GNU C11 |
TESTS |
51 |
93 |
100966400 |
|
|
116388231 |
weddew |
D |
May 16, 2021, 10:12 a.m. |
OK |
GNU C++11 |
TESTS |
51 |
31 |
102400 |
|
|
116408904 |
AIM9L |
D |
May 16, 2021, 1:52 p.m. |
OK |
GNU C++11 |
TESTS |
51 |
31 |
102400 |
|
|
116442172 |
linuxll |
D |
May 17, 2021, 2:13 a.m. |
OK |
GNU C++11 |
TESTS |
51 |
31 |
102400 |
|
|
116409948 |
AIM9L |
D |
May 16, 2021, 2:05 p.m. |
OK |
GNU C++11 |
TESTS |
51 |
31 |
102400 |
|
|
116430981 |
cjjst123 |
D |
May 16, 2021, 7:03 p.m. |
OK |
GNU C++11 |
TESTS |
51 |
31 |
614400 |
|
|
116392492 |
Richard_ZRC |
D |
May 16, 2021, 10:51 a.m. |
OK |
GNU C++11 |
TESTS |
51 |
31 |
921600 |
|
|
116389469 |
MayFlyyh |
D |
May 16, 2021, 10:22 a.m. |
OK |
GNU C++11 |
TESTS |
51 |
31 |
1843200 |
|
|
116444430 |
MayFlyyh |
D |
May 17, 2021, 3:24 a.m. |
OK |
GNU C++11 |
TESTS |
51 |
31 |
8192000 |
|
|
116410005 |
ridiculous_dzx |
D |
May 16, 2021, 2:06 p.m. |
OK |
GNU C++11 |
TESTS |
51 |
31 |
50278400 |
|
|
116440920 |
MayFlyyh |
D |
May 17, 2021, 1:20 a.m. |
OK |
GNU C++11 |
TESTS |
51 |
31 |
96153600 |
|
|
116420890 |
Cantor. |
D |
May 16, 2021, 4:19 p.m. |
OK |
GNU C++14 |
TESTS |
51 |
31 |
102400 |
|
|
116386321 |
Never_Do_it |
D |
May 16, 2021, 10:01 a.m. |
OK |
GNU C++14 |
TESTS |
51 |
31 |
102400 |
|
|
116448656 |
Hidder |
D |
May 17, 2021, 5:01 a.m. |
OK |
GNU C++14 |
TESTS |
51 |
31 |
3584000 |
|
|
116397278 |
_Subrata |
D |
May 16, 2021, 11:38 a.m. |
OK |
GNU C++14 |
TESTS |
51 |
46 |
102400 |
|
|
116395880 |
Sumeet_mishra |
D |
May 16, 2021, 11:24 a.m. |
OK |
GNU C++14 |
TESTS |
51 |
46 |
102400 |
|
|
116388288 |
isumit15 |
D |
May 16, 2021, 10:13 a.m. |
OK |
GNU C++14 |
TESTS |
51 |
46 |
102400 |
|
|
116403209 |
n00bie_1004 |
D |
May 16, 2021, 12:44 p.m. |
OK |
GNU C++14 |
TESTS |
51 |
46 |
204800 |
|
|
116404723 |
tnaito |
D |
May 16, 2021, 1:02 p.m. |
OK |
GNU C++14 |
TESTS |
51 |
46 |
12902400 |
|
|
116433122 |
Prime_08 |
D |
May 16, 2021, 7:50 p.m. |
OK |
GNU C++14 |
TESTS |
51 |
46 |
25088000 |
|
|
116428657 |
jojonicho |
D |
May 16, 2021, 6:21 p.m. |
OK |
GNU C++14 |
TESTS |
51 |
46 |
25088000 |
|
|
116451456 |
Apolis |
D |
May 17, 2021, 5:49 a.m. |
OK |
GNU C++17 |
TESTS |
51 |
30 |
32358400 |
|
|
116444170 |
Firefrog418 |
D |
May 17, 2021, 3:18 a.m. |
OK |
GNU C++17 |
TESTS |
51 |
31 |
102400 |
|
|
116443684 |
SadFriedRice |
D |
May 17, 2021, 3:05 a.m. |
OK |
GNU C++17 |
TESTS |
51 |
31 |
102400 |
|
|
116437718 |
drawing_dead |
D |
May 16, 2021, 10:33 p.m. |
OK |
GNU C++17 |
TESTS |
51 |
31 |
102400 |
|
|
116436329 |
lxyb |
D |
May 16, 2021, 9:30 p.m. |
OK |
GNU C++17 |
TESTS |
51 |
31 |
102400 |
|
|
116429014 |
luckyanthonyan |
D |
May 16, 2021, 6:28 p.m. |
OK |
GNU C++17 |
TESTS |
51 |
31 |
102400 |
|
|
116428721 |
motorcycle |
D |
May 16, 2021, 6:22 p.m. |
OK |
GNU C++17 |
TESTS |
51 |
31 |
102400 |
|
|
116422296 |
gowtham_g30 |
D |
May 16, 2021, 4:40 p.m. |
OK |
GNU C++17 |
TESTS |
51 |
31 |
204800 |
|
|
116410185 |
DrSwad |
D |
May 16, 2021, 2:08 p.m. |
OK |
GNU C++17 |
TESTS |
51 |
31 |
204800 |
|
|
116434537 |
Jonathan1234 |
D |
May 16, 2021, 8:28 p.m. |
OK |
GNU C++17 |
TESTS |
51 |
31 |
409600 |
|
|
116418139 |
shuaishuaishuai |
D |
May 16, 2021, 3:43 p.m. |
OK |
GNU C++17 (64) |
TESTS |
51 |
31 |
102400 |
|
|
116417546 |
ankurkayal |
D |
May 16, 2021, 3:35 p.m. |
OK |
GNU C++17 (64) |
TESTS |
51 |
31 |
102400 |
|
|
116414756 |
Rock_Lee08 |
D |
May 16, 2021, 3:02 p.m. |
OK |
GNU C++17 (64) |
TESTS |
51 |
31 |
102400 |
|
|
116406689 |
childofcuriosity |
D |
May 16, 2021, 1:25 p.m. |
OK |
GNU C++17 (64) |
TESTS |
51 |
31 |
102400 |
|
|
116406171 |
childofcuriosity |
D |
May 16, 2021, 1:18 p.m. |
OK |
GNU C++17 (64) |
TESTS |
51 |
31 |
102400 |
|
|
116403417 |
childofcuriosity |
D |
May 16, 2021, 12:47 p.m. |
OK |
GNU C++17 (64) |
TESTS |
51 |
31 |
102400 |
|
|
116399106 |
algopedia.ai |
D |
May 16, 2021, 11:59 a.m. |
OK |
GNU C++17 (64) |
TESTS |
51 |
31 |
102400 |
|
|
116409716 |
always_rstrive |
D |
May 16, 2021, 2:02 p.m. |
OK |
GNU C++17 (64) |
TESTS |
51 |
31 |
204800 |
|
|
116420955 |
pikel_rik |
D |
May 16, 2021, 4:20 p.m. |
OK |
GNU C++17 (64) |
TESTS |
51 |
46 |
102400 |
|
|
116418097 |
prottoyfuad |
D |
May 16, 2021, 3:42 p.m. |
OK |
GNU C++17 (64) |
TESTS |
51 |
46 |
102400 |
|
|
116405160 |
bluesky111 |
D |
May 16, 2021, 1:07 p.m. |
OK |
Java 11 |
TESTS |
51 |
202 |
0 |
|
|
116395030 |
hellstar7621 |
D |
May 16, 2021, 11:16 a.m. |
OK |
Java 11 |
TESTS |
51 |
249 |
40652800 |
|
|
116423270 |
dakshkamboj |
D |
May 16, 2021, 4:54 p.m. |
OK |
Java 11 |
TESTS |
51 |
249 |
40755200 |
|
|
116449093 |
Lelouch_1 |
D |
May 17, 2021, 5:09 a.m. |
OK |
Java 11 |
TESTS |
51 |
264 |
40652800 |
|
|
116391983 |
LionHeart20 |
D |
May 16, 2021, 10:46 a.m. |
OK |
Java 11 |
TESTS |
51 |
264 |
78540800 |
|
|
116391143 |
YuekunWang |
D |
May 16, 2021, 10:37 a.m. |
OK |
Java 11 |
TESTS |
51 |
265 |
42086400 |
|
|
116437763 |
jamesfan961101 |
D |
May 16, 2021, 10:36 p.m. |
OK |
Java 11 |
TESTS |
51 |
265 |
42700800 |
|
|
116424966 |
mohitn |
D |
May 16, 2021, 5:20 p.m. |
OK |
Java 11 |
TESTS |
51 |
280 |
40652800 |
|
|
116443247 |
pikachu_pika_pika |
D |
May 17, 2021, 2:51 a.m. |
OK |
Java 11 |
TESTS |
51 |
280 |
40755200 |
|
|
116448000 |
herschelle19045 |
D |
May 17, 2021, 4:48 a.m. |
OK |
Java 11 |
TESTS |
51 |
280 |
42086400 |
|
|
116400915 |
7dan |
D |
May 16, 2021, 12:19 p.m. |
OK |
Java 8 |
TESTS |
51 |
171 |
38604800 |
|
|
116436177 |
Agnimandur |
D |
May 16, 2021, 9:24 p.m. |
OK |
Java 8 |
TESTS |
51 |
171 |
38912000 |
|
|
116384462 |
This_is_the_one |
D |
May 16, 2021, 9:56 a.m. |
OK |
Java 8 |
TESTS |
51 |
186 |
37068800 |
|
|
116392707 |
_robindhankhar |
D |
May 16, 2021, 10:54 a.m. |
OK |
Java 8 |
TESTS |
51 |
186 |
38707200 |
|
|
116409743 |
Frank0628 |
D |
May 16, 2021, 2:02 p.m. |
OK |
Java 8 |
TESTS |
51 |
186 |
39321600 |
|
|
116435477 |
Katushechka |
D |
May 16, 2021, 8:57 p.m. |
OK |
Java 8 |
TESTS |
51 |
187 |
0 |
|
|
116397089 |
This_is_the_one |
D |
May 16, 2021, 11:36 a.m. |
OK |
Java 8 |
TESTS |
51 |
187 |
38400000 |
|
|
116440004 |
TheSawan |
D |
May 17, 2021, 12:38 a.m. |
OK |
Java 8 |
TESTS |
51 |
202 |
38707200 |
|
|
116411708 |
chinmaya21 |
D |
May 16, 2021, 2:27 p.m. |
OK |
Java 8 |
TESTS |
51 |
202 |
40038400 |
|
|
116451557 |
cosinechicken |
D |
May 17, 2021, 5:51 a.m. |
OK |
Java 8 |
TESTS |
51 |
202 |
40960000 |
|
|
116427448 |
koper |
D |
May 16, 2021, 6:01 p.m. |
OK |
Kotlin |
TESTS |
51 |
249 |
42086400 |
|
|
116451515 |
cosinechicken |
D |
May 17, 2021, 5:50 a.m. |
OK |
MS C++ 2017 |
TESTS |
51 |
46 |
26521600 |
|
|
116441806 |
zyj2012190230 |
D |
May 17, 2021, 1:58 a.m. |
OK |
MS C++ 2017 |
TESTS |
51 |
124 |
201216000 |
|
|
116435740 |
fgwiebfaoish |
D |
May 16, 2021, 9:06 p.m. |
OK |
.NET Core C# |
TESTS |
51 |
108 |
26009600 |
|
|
116440045 |
sakapon |
D |
May 17, 2021, 12:40 a.m. |
OK |
.NET Core C# |
TESTS |
51 |
265 |
25497600 |
|
|
116398033 |
henrychenOutlook |
D |
May 16, 2021, 11:46 a.m. |
OK |
Node.js |
TESTS |
51 |
592 |
242585600 |
|
|
116397844 |
henrychenOutlook |
D |
May 16, 2021, 11:44 a.m. |
OK |
Node.js |
TESTS |
51 |
655 |
242483200 |
|
|
116414737 |
shehebe |
D |
May 16, 2021, 3:02 p.m. |
OK |
PyPy 2 |
TESTS |
51 |
576 |
102195200 |
|
|
116395286 |
snape_here |
D |
May 16, 2021, 11:19 a.m. |
OK |
PyPy 2 |
TESTS |
51 |
935 |
70348800 |
|
|
116436443 |
silvertint |
D |
May 16, 2021, 9:35 p.m. |
OK |
PyPy 3 |
TESTS |
51 |
124 |
2355200 |
|
|
116395677 |
recuraki |
D |
May 16, 2021, 11:22 a.m. |
OK |
PyPy 3 |
TESTS |
51 |
155 |
3584000 |
|
|
116386844 |
lakshay_jain |
D |
May 16, 2021, 10:04 a.m. |
OK |
PyPy 3 |
TESTS |
51 |
202 |
28569600 |
|
|
116405139 |
Soul_Silver |
D |
May 16, 2021, 1:07 p.m. |
OK |
PyPy 3 |
TESTS |
51 |
217 |
3379200 |
|
|
116430306 |
luckyanthonyan |
D |
May 16, 2021, 6:50 p.m. |
OK |
PyPy 3 |
TESTS |
51 |
233 |
28774400 |
|
|
116436296 |
thhsu |
D |
May 16, 2021, 9:28 p.m. |
OK |
PyPy 3 |
TESTS |
51 |
233 |
84275200 |
|
|
116449718 |
ShantanuTripathi |
D |
May 17, 2021, 5:19 a.m. |
OK |
PyPy 3 |
TESTS |
51 |
248 |
30105600 |
|
|
116389707 |
dallasyan |
D |
May 16, 2021, 10:24 a.m. |
OK |
PyPy 3 |
TESTS |
51 |
249 |
30003200 |
|
|
116397022 |
rivnam |
D |
May 16, 2021, 11:35 a.m. |
OK |
PyPy 3 |
TESTS |
51 |
280 |
29593600 |
|
|
116397310 |
rivnam |
D |
May 16, 2021, 11:38 a.m. |
OK |
PyPy 3 |
TESTS |
51 |
280 |
32768000 |
|
|
116405337 |
bqn |
D |
May 16, 2021, 1:09 p.m. |
OK |
Rust |
TESTS |
51 |
748 |
2457600 |
|
|
remove filters
Back to search problems