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"Let's define a cyclic shift of some string s as a transformation from s_1 s_2 ... s_{n-1} s_{n} into s_{n} s_1 s_2 ... s_{n-1} . In other words, you take one last character s_n and place it before the first character while moving all other characters to the right. You are given a binary string s (a string consisting of only 0-s and/or 1-s). In one operation, you can choose any substring s_l s_{l+1} ... s_r ( 1 <= l < r <= |s| ) and cyclically shift it. The cost of such operation is equal to r - l + 1 (or the length of the chosen substring). You can perform the given operation any number of times. What is the minimum total cost to make s sorted in non-descending order? The first line contains a single integer t ( 1 <= t <= 10^4 ) -- the number of test cases. The first and only line of each test case contains a binary string s ( 2 <= |s| <= 2 cdot 10^5 ; s_i in {0, 1}) -- the string you need to sort. Additional constraint on the input: the sum of lengths of strings over all test cases doesn't exceed 2 cdot 10^5 . For each test case, print the single integer -- the minimum total cost to make string sorted using operation above any number of times. In the first test case, you can choose the whole string and perform a cyclic shift: 10 rightarrow 01. The length of the substring is 2 , so the cost is 2 . In the second test case, the string is already sorted, so you don't need to perform any operations. In the third test case, one of the optimal strategies is the next: "... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
262115327 |
coolboy7724 |
B |
May 22, 2024, 8:44 a.m. |
OK |
C# 10 |
TESTS |
15 |
93 |
614400 |
|
1000 |
261587323 |
A1ternate |
B |
May 19, 2024, 12:44 a.m. |
OK |
C# 10 |
TESTS |
15 |
93 |
614400 |
|
1000 |
263610756 |
sumitst05_ |
B |
June 1, 2024, 10:07 a.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
15 |
46 |
0 |
|
1000 |
263255669 |
Shonko006 |
B |
May 30, 2024, 1:28 p.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
15 |
46 |
0 |
|
1000 |
263240111 |
rolex009 |
B |
May 30, 2024, 12:08 p.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
15 |
46 |
0 |
|
1000 |
263229838 |
shimingy_diaa07 |
B |
May 30, 2024, 11:26 a.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
15 |
46 |
0 |
|
1000 |
263034355 |
Cinnaki |
B |
May 28, 2024, 3:43 p.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
15 |
46 |
0 |
|
1000 |
262503568 |
khan.daniyal1329 |
B |
May 25, 2024, 11:34 a.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
15 |
46 |
0 |
|
1000 |
262387646 |
vjudge3 |
B |
May 24, 2024, 12:54 p.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
15 |
46 |
0 |
|
1000 |
262124775 |
Bobchik |
B |
May 22, 2024, 9:57 a.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
15 |
46 |
0 |
|
1000 |
261661127 |
jaiswalXKrish |
B |
May 19, 2024, 1:57 p.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
15 |
46 |
0 |
|
1000 |
261658971 |
lzm_555994 |
B |
May 19, 2024, 1:39 p.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
15 |
46 |
0 |
|
1000 |
263703247 |
harshverma24 |
B |
June 2, 2024, 5:36 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
15 |
46 |
0 |
|
1000 |
263698696 |
ap_7163 |
B |
June 2, 2024, 4:32 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
15 |
46 |
0 |
|
1000 |
263698687 |
mr_a5 |
B |
June 2, 2024, 4:31 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
15 |
46 |
0 |
|
1000 |
263680490 |
Satya.akeA |
B |
June 1, 2024, 8:53 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
15 |
46 |
0 |
|
1000 |
263664478 |
overjoyed22 |
B |
June 1, 2024, 5:36 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
15 |
46 |
0 |
|
1000 |
263651194 |
Amazed |
B |
June 1, 2024, 3:44 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
15 |
46 |
0 |
|
1000 |
263625933 |
aryanmishra12112003 |
B |
June 1, 2024, 12:03 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
15 |
46 |
0 |
|
1000 |
263602895 |
animeshmadaan09 |
B |
June 1, 2024, 9 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
15 |
46 |
0 |
|
1000 |
263589062 |
KolinYan |
B |
June 1, 2024, 7:06 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
15 |
46 |
0 |
|
1000 |
263580198 |
Saikot_Das |
B |
June 1, 2024, 5:49 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
15 |
46 |
0 |
|
1000 |
263379091 |
kk2311 |
B |
May 30, 2024, 7:06 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
15 |
46 |
0 |
|
1000 |
263372182 |
kd_rush |
B |
May 30, 2024, 5:56 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
15 |
46 |
0 |
|
1000 |
263220632 |
opbot_xd |
B |
May 30, 2024, 10:15 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
15 |
46 |
0 |
|
1000 |
263214089 |
Rakshit_1 |
B |
May 30, 2024, 8:54 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
15 |
46 |
0 |
|
1000 |
263191835 |
darkwizardd |
B |
May 30, 2024, 12:04 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
15 |
46 |
0 |
|
1000 |
263190135 |
ImSarthak |
B |
May 29, 2024, 11:07 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
15 |
46 |
0 |
|
1000 |
263184598 |
ahmedyoussefg |
B |
May 29, 2024, 8:57 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
15 |
46 |
0 |
|
1000 |
263170030 |
not_aryan |
B |
May 29, 2024, 4:57 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
15 |
46 |
0 |
|
1000 |
263129744 |
omium |
B |
May 29, 2024, 11:02 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
15 |
46 |
0 |
|
1000 |
263123348 |
lost_martian |
B |
May 29, 2024, 10:06 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
15 |
46 |
0 |
|
1000 |
261927104 |
sharanyabaidya2020 |
B |
May 20, 2024, 7:02 p.m. |
OK |
GNU C11 |
TESTS |
15 |
61 |
204800 |
|
1000 |
262266752 |
muhaimen_nemesis |
B |
May 23, 2024, 1:40 p.m. |
OK |
GNU C11 |
TESTS |
15 |
61 |
307200 |
|
1000 |
263203185 |
debrup_prime |
B |
May 30, 2024, 5:55 a.m. |
OK |
GNU C11 |
TESTS |
15 |
62 |
2048000 |
|
1000 |
262870987 |
higher123 |
B |
May 27, 2024, 11:24 a.m. |
OK |
GNU C11 |
TESTS |
15 |
77 |
204800 |
|
1000 |
263118643 |
decentcoder |
B |
May 29, 2024, 9:29 a.m. |
OK |
GNU C11 |
TESTS |
15 |
77 |
307200 |
|
1000 |
262275603 |
yui0 |
B |
May 23, 2024, 2:49 p.m. |
OK |
GNU C11 |
TESTS |
15 |
77 |
307200 |
|
1000 |
263641252 |
nguyenquocthao00 |
B |
June 1, 2024, 2:18 p.m. |
OK |
Go |
TESTS |
15 |
62 |
512000 |
|
1000 |
260488375 |
nguyenquocthao00 |
B |
May 11, 2024, 5:43 a.m. |
OK |
Go |
TESTS |
15 |
62 |
512000 |
|
1000 |
260030359 |
botayhard |
B |
May 8, 2024, 5:12 p.m. |
OK |
Go |
TESTS |
15 |
77 |
8089600 |
|
1000 |
262833415 |
vnsh |
B |
May 27, 2024, 6:08 a.m. |
OK |
Go |
TESTS |
15 |
218 |
1433600 |
|
1000 |
262041912 |
burg113 |
B |
May 21, 2024, 3:31 p.m. |
OK |
Go |
TESTS |
15 |
218 |
1433600 |
|
1000 |
259890503 |
bhavya_boda |
B |
May 7, 2024, 2:39 p.m. |
OK |
Java 21 |
TESTS |
15 |
234 |
716800 |
|
1000 |
261710362 |
grace.rd.xu |
B |
May 20, 2024, 12:21 a.m. |
OK |
Java 21 |
TESTS |
15 |
234 |
819200 |
|
1000 |
260928124 |
yashmishra.vapi |
B |
May 14, 2024, 12:47 p.m. |
OK |
Java 21 |
TESTS |
15 |
234 |
1433600 |
|
1000 |
263620828 |
harsh_chib70 |
B |
June 1, 2024, 11:24 a.m. |
OK |
Java 21 |
TESTS |
15 |
249 |
512000 |
|
1000 |
260007264 |
Yash9890 |
B |
May 8, 2024, 1:39 p.m. |
OK |
Java 21 |
TESTS |
15 |
250 |
307200 |
|
1000 |
260910684 |
I_domt_Kmow |
B |
May 14, 2024, 10:31 a.m. |
OK |
Java 21 |
TESTS |
15 |
264 |
307200 |
|
1000 |
260070743 |
PoseidonXI |
B |
May 9, 2024, 4:58 a.m. |
OK |
Java 21 |
TESTS |
15 |
264 |
819200 |
|
1000 |
260070578 |
anshpatel2434 |
B |
May 9, 2024, 4:56 a.m. |
OK |
Java 21 |
TESTS |
15 |
265 |
102400 |
|
1000 |
261113070 |
new2ac |
B |
May 16, 2024, 12:59 a.m. |
OK |
Java 21 |
TESTS |
15 |
265 |
819200 |
|
1000 |
260554159 |
superbryantyu |
B |
May 11, 2024, 3:23 p.m. |
OK |
Java 21 |
TESTS |
15 |
280 |
614400 |
|
1000 |
262412836 |
sam_20101999 |
B |
May 24, 2024, 4:22 p.m. |
OK |
Java 8 |
TESTS |
15 |
140 |
0 |
|
1000 |
261737846 |
yvbf |
B |
May 20, 2024, 7:46 a.m. |
OK |
Java 8 |
TESTS |
15 |
140 |
0 |
|
1000 |
261321257 |
.shinchan_ |
B |
May 17, 2024, 11:32 a.m. |
OK |
Java 8 |
TESTS |
15 |
140 |
0 |
|
1000 |
261310833 |
dogfootone |
B |
May 17, 2024, 10:04 a.m. |
OK |
Java 8 |
TESTS |
15 |
140 |
0 |
|
1000 |
260564872 |
suyash.211.sn |
B |
May 11, 2024, 5:07 p.m. |
OK |
Java 8 |
TESTS |
15 |
140 |
0 |
|
1000 |
260026715 |
angshn |
B |
May 8, 2024, 4:34 p.m. |
OK |
Java 8 |
TESTS |
15 |
155 |
0 |
|
1000 |
262220560 |
Sumitsingh7 |
B |
May 23, 2024, 7:16 a.m. |
OK |
Java 8 |
TESTS |
15 |
171 |
7987200 |
|
1000 |
261741756 |
Saurabh124 |
B |
May 20, 2024, 8:01 a.m. |
OK |
Java 8 |
TESTS |
15 |
186 |
0 |
|
1000 |
259881174 |
Ovetsar_ilish |
B |
May 7, 2024, 1:23 p.m. |
OK |
Java 8 |
TESTS |
15 |
186 |
0 |
|
1000 |
260029056 |
Trapti00712 |
B |
May 8, 2024, 4:59 p.m. |
OK |
Java 8 |
TESTS |
15 |
187 |
0 |
|
1000 |
259864061 |
linxiaotian |
B |
May 7, 2024, 11:07 a.m. |
OK |
Kotlin 1.9 |
TESTS |
15 |
202 |
1433600 |
|
1000 |
261326705 |
gray-white-yellow |
B |
May 17, 2024, 12:15 p.m. |
OK |
Kotlin 1.9 |
TESTS |
15 |
203 |
0 |
|
1000 |
261288311 |
Hamza_Refai |
B |
May 17, 2024, 6:44 a.m. |
OK |
Kotlin 1.9 |
TESTS |
15 |
203 |
0 |
|
1000 |
262360173 |
Void_Raghav10 |
B |
May 24, 2024, 9:10 a.m. |
OK |
Kotlin 1.9 |
TESTS |
15 |
234 |
0 |
|
1000 |
262401906 |
chunza2542 |
B |
May 24, 2024, 2:48 p.m. |
OK |
Node.js |
TESTS |
15 |
218 |
8601600 |
|
1000 |
259881027 |
Salamander_ |
B |
May 7, 2024, 1:22 p.m. |
OK |
Node.js |
TESTS |
15 |
233 |
10547200 |
|
1000 |
263009211 |
parth_7042 |
B |
May 28, 2024, 12:23 p.m. |
OK |
PHP |
TESTS |
15 |
108 |
18944000 |
|
1000 |
262485951 |
klu-2100030642 |
B |
May 25, 2024, 9:10 a.m. |
OK |
PyPy 3 |
TESTS |
15 |
140 |
4505600 |
|
1000 |
261268124 |
biniyamnegasa |
B |
May 17, 2024, 2:55 a.m. |
OK |
PyPy 3 |
TESTS |
15 |
140 |
7680000 |
|
1000 |
263248266 |
sathwik11112005 |
B |
May 30, 2024, 12:34 p.m. |
OK |
PyPy 3 |
TESTS |
15 |
187 |
3686400 |
|
1000 |
261337281 |
lo_krlo_baatt |
B |
May 17, 2024, 1:37 p.m. |
OK |
PyPy 3 |
TESTS |
15 |
187 |
3993600 |
|
1000 |
261942255 |
samosamo |
B |
May 20, 2024, 11:01 p.m. |
OK |
PyPy 3 |
TESTS |
15 |
187 |
6246400 |
|
1000 |
260712238 |
ladderwarrior |
B |
May 12, 2024, 8:30 p.m. |
OK |
PyPy 3 |
TESTS |
15 |
217 |
3174400 |
|
1000 |
262617724 |
VS34 |
B |
May 25, 2024, 7:16 p.m. |
OK |
PyPy 3 |
TESTS |
15 |
218 |
3174400 |
|
1000 |
260119055 |
AlgorithmAcee |
B |
May 9, 2024, 12:17 p.m. |
OK |
PyPy 3 |
TESTS |
15 |
218 |
3379200 |
|
1000 |
262909966 |
V_1995 |
B |
May 27, 2024, 4:30 p.m. |
OK |
PyPy 3 |
TESTS |
15 |
249 |
4915200 |
|
1000 |
261223613 |
ZhuravlevAlexander_01 |
B |
May 16, 2024, 4:06 p.m. |
OK |
PyPy 3 |
TESTS |
15 |
249 |
5120000 |
|
1000 |
262058531 |
ScitusSnake |
B |
May 21, 2024, 5:47 p.m. |
OK |
PyPy 3-64 |
TESTS |
15 |
78 |
3481600 |
|
1000 |
261116074 |
praveen2912 |
B |
May 16, 2024, 2:01 a.m. |
OK |
PyPy 3-64 |
TESTS |
15 |
93 |
2252800 |
|
1000 |
260827565 |
Youarenotgood |
B |
May 13, 2024, 4:05 p.m. |
OK |
PyPy 3-64 |
TESTS |
15 |
93 |
2969600 |
|
1000 |
263482806 |
dumEinstein |
B |
May 31, 2024, 11:32 a.m. |
OK |
PyPy 3-64 |
TESTS |
15 |
93 |
3174400 |
|
1000 |
261538182 |
bergus |
B |
May 18, 2024, 1:48 p.m. |
OK |
PyPy 3-64 |
TESTS |
15 |
93 |
3379200 |
|
1000 |
260997164 |
MdAbedin |
B |
May 15, 2024, 3:22 a.m. |
OK |
PyPy 3-64 |
TESTS |
15 |
93 |
3584000 |
|
1000 |
260821242 |
123Summertime |
B |
May 13, 2024, 3:19 p.m. |
OK |
PyPy 3-64 |
TESTS |
15 |
93 |
3686400 |
|
1000 |
260103891 |
madboii |
B |
May 9, 2024, 10:19 a.m. |
OK |
PyPy 3-64 |
TESTS |
15 |
108 |
2150400 |
|
1000 |
259935350 |
varrick |
B |
May 8, 2024, 12:20 a.m. |
OK |
PyPy 3-64 |
TESTS |
15 |
108 |
2150400 |
|
1000 |
261095140 |
Padmnabhuno |
B |
May 15, 2024, 6:48 p.m. |
OK |
PyPy 3-64 |
TESTS |
15 |
108 |
2252800 |
|
1000 |
262653211 |
1nurtas |
B |
May 26, 2024, 5:40 a.m. |
OK |
Python 3 |
TESTS |
15 |
93 |
0 |
|
1000 |
261456799 |
AaryaD2005 |
B |
May 18, 2024, 4:24 a.m. |
OK |
Python 3 |
TESTS |
15 |
93 |
0 |
|
1000 |
259892982 |
NsrEZ |
B |
May 7, 2024, 3 p.m. |
OK |
Python 3 |
TESTS |
15 |
93 |
512000 |
|
1000 |
263560921 |
vatsaltrivedi509 |
B |
June 1, 2024, 1:24 a.m. |
OK |
Python 3 |
TESTS |
15 |
93 |
1638400 |
|
1000 |
262816728 |
heber.alturria |
B |
May 27, 2024, 3:02 a.m. |
OK |
Python 3 |
TESTS |
15 |
93 |
1638400 |
|
1000 |
263052330 |
_rahul11_ |
B |
May 28, 2024, 6:20 p.m. |
OK |
Python 3 |
TESTS |
15 |
108 |
0 |
|
1000 |
262976071 |
LuosKrad |
B |
May 28, 2024, 7:43 a.m. |
OK |
Python 3 |
TESTS |
15 |
108 |
0 |
|
1000 |
262905785 |
21b01a1239 |
B |
May 27, 2024, 3:54 p.m. |
OK |
Python 3 |
TESTS |
15 |
109 |
0 |
|
1000 |
261494000 |
JR1der |
B |
May 18, 2024, 8:49 a.m. |
OK |
Python 3 |
TESTS |
15 |
109 |
0 |
|
1000 |
261429766 |
plusplus6408 |
B |
May 17, 2024, 7:46 p.m. |
OK |
Python 3 |
TESTS |
15 |
109 |
0 |
|
1000 |
261137722 |
qqqqc |
B |
May 16, 2024, 3:59 a.m. |
OK |
Rust 2021 |
TESTS |
15 |
62 |
0 |
|
1000 |
259865524 |
l_y_f |
B |
May 7, 2024, 11:20 a.m. |
OK |
Rust 2021 |
TESTS |
15 |
62 |
0 |
|
1000 |
263168472 |
n0b0dy01 |
B |
May 29, 2024, 4:35 p.m. |
OK |
Rust 2021 |
TESTS |
15 |
62 |
2764800 |
|
1000 |
remove filters
Back to search problems