Codeforces Round 1054 (Div. 3)

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
2149 Codeforces Round 1054 (Div. 3) FINISHED False 8100 17594723 Sept. 25, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 19202 ) D A and B PROGRAMMING strings

Given a string (s) of length (n), consisting only of the characters ' a ' and ' b '. In one operation, you can choose a position (i) ((1 \le i \le n-1)) and swap the neighboring characters (s_i) and (s_{i+1}). You need to perform the minimum number of operations to ensure that all characters of one type (either (a) or (b)) are located strictly together, forming exactly one continuous block. Characters of the other type can be positioned either before or after this block, forming two (possibly empty) blocks. Examples of valid final forms: ' aaabbbaaa ' — all ' b 's are located together (one block), ' a 's can be both before and after this block; ' bbbaaaaaabbb ' — all ' a 's together, ' b 's are at the edges of the string; ' aaaaabbbb ' or ' bbbbaaaaa ' — both types of characters form one continuous block each. You need to find the minimum number of described operations required to achieve the specified state. Each test consists of several test cases. The first line contains one integer (t) ((1 \le t \le 10^4)) — the number of test cases. The description of test cases follows. The first line of each test case contains one integer (n) ((1 \le n \le 2 \cdot 10^5)) — the length of the string (s). The second line contains the string (s) of length (n), consisting only of the characters ' a ' and ' b '. It is guaranteed that the sum of the values of (n) over all test cases does not exceed (2 \cdot 10^5). For each test case, output one integer — the minimum number of operations required for all characters of one of the two types to form a single continuous block. In the first test case, the initial string is ' abab ': by swapping the neighboring characters at positions (2) and (3), we get the string ' aabb '; or by swapping the characters at positions (1) and (2), we get the string ' baab '. In the fifth input test case, the string consists of a single character ' b '. The single c

Tutorials

__rose

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
340524497 ksandr1v D Sept. 25, 2025, 7:08 p.m. OK C# 13 TESTS 11 217 11468800
340567962 sachin_3059 D Sept. 26, 2025, 6 a.m. OK C++17 (GCC 7-32) TESTS 13 46 0
340567805 arjunpundir D Sept. 26, 2025, 5:59 a.m. OK C++17 (GCC 7-32) TESTS 13 46 0
340566866 neerajkumar4 D Sept. 26, 2025, 5:49 a.m. OK C++17 (GCC 7-32) TESTS 11 46 0
340566575 wujijlc D Sept. 26, 2025, 5:45 a.m. OK C++17 (GCC 7-32) TESTS 11 46 0
340561871 fyv233 D Sept. 26, 2025, 4:57 a.m. OK C++17 (GCC 7-32) TESTS 11 46 0
340560031 123qaq D Sept. 26, 2025, 4:41 a.m. OK C++17 (GCC 7-32) TESTS 11 46 0
340559811 praket24 D Sept. 26, 2025, 4:39 a.m. OK C++17 (GCC 7-32) TESTS 11 46 0
340559503 skullcrusher_2104 D Sept. 26, 2025, 4:36 a.m. OK C++17 (GCC 7-32) TESTS 11 46 0
340552631 satyams100 D Sept. 26, 2025, 2:58 a.m. OK C++17 (GCC 7-32) TESTS 11 46 0
340551141 sunj D Sept. 26, 2025, 2:36 a.m. OK C++17 (GCC 7-32) TESTS 11 46 0
340563803 -SOLOM- D Sept. 26, 2025, 5:15 a.m. OK C++20 (GCC 13-64) TESTS 11 46 0
340556409 chenkaiwen D Sept. 26, 2025, 3:52 a.m. OK C++20 (GCC 13-64) TESTS 11 46 0
340556223 Samarth_Udagi D Sept. 26, 2025, 3:49 a.m. OK C++20 (GCC 13-64) TESTS 11 46 0
340551965 FlourishAden D Sept. 26, 2025, 2:49 a.m. OK C++20 (GCC 13-64) TESTS 11 46 0
340551568 6434554613 D Sept. 26, 2025, 2:43 a.m. OK C++20 (GCC 13-64) TESTS 11 46 0
340544419 theAhsanMind D Sept. 26, 2025, 12:35 a.m. OK C++20 (GCC 13-64) TESTS 11 46 0
340540717 itsiftikar02 D Sept. 25, 2025, 11:01 p.m. OK C++20 (GCC 13-64) TESTS 11 46 0
340539562 An9on D Sept. 25, 2025, 10:30 p.m. OK C++20 (GCC 13-64) TESTS 11 46 0
340536618 M0NTANA D Sept. 25, 2025, 9:39 p.m. OK C++20 (GCC 13-64) TESTS 11 46 0
340533889 Omqr D Sept. 25, 2025, 9:03 p.m. OK C++20 (GCC 13-64) TESTS 11 46 0
340567539 pinkPanties D Sept. 26, 2025, 5:56 a.m. OK C++23 (GCC 14-64, msys2) TESTS 13 46 0
340566958 usedchang D Sept. 26, 2025, 5:50 a.m. OK C++23 (GCC 14-64, msys2) TESTS 11 46 0
340566121 __90m3 D Sept. 26, 2025, 5:40 a.m. OK C++23 (GCC 14-64, msys2) TESTS 11 46 0
340565060 OTTFF D Sept. 26, 2025, 5:29 a.m. OK C++23 (GCC 14-64, msys2) TESTS 11 46 0
340564900 Ezreal_ D Sept. 26, 2025, 5:27 a.m. OK C++23 (GCC 14-64, msys2) TESTS 11 46 0
340563594 shihen D Sept. 26, 2025, 5:13 a.m. OK C++23 (GCC 14-64, msys2) TESTS 11 46 0
340560947 Rodri1721 D Sept. 26, 2025, 4:49 a.m. OK C++23 (GCC 14-64, msys2) TESTS 11 46 0
340560885 imanol23_ D Sept. 26, 2025, 4:48 a.m. OK C++23 (GCC 14-64, msys2) TESTS 11 46 0
340558577 MohamedA_ D Sept. 26, 2025, 4:25 a.m. OK C++23 (GCC 14-64, msys2) TESTS 11 46 0
340556531 poltergistrespawn17 D Sept. 26, 2025, 3:54 a.m. OK C++23 (GCC 14-64, msys2) TESTS 11 46 0
340532288 1435730 D Sept. 25, 2025, 8:39 p.m. OK GNU C11 TESTS 11 46 307200
340558652 a-khushal D Sept. 26, 2025, 4:26 a.m. OK GNU C11 TESTS 11 92 8396800
340521970 Saksham_3110 D Sept. 25, 2025, 6:42 p.m. OK Java 21 TESTS 11 233 819200
340503468 s_mahata D Sept. 25, 2025, 4:45 p.m. OK Java 21 TESTS 10 249 204800
340507468 mayurbhai D Sept. 25, 2025, 4:53 p.m. OK Java 21 TESTS 10 249 512000
340513249 Smit_Soni D Sept. 25, 2025, 5:28 p.m. OK Java 21 TESTS 10 264 716800
340524202 Satyam_08 D Sept. 25, 2025, 7:05 p.m. OK Java 21 TESTS 11 265 204800
340508082 NS-KAL D Sept. 25, 2025, 4:55 p.m. OK Java 21 TESTS 10 265 716800
340564414 mzip D Sept. 26, 2025, 5:22 a.m. OK Java 21 TESTS 11 265 1536000
340507920 Ayush_Raj_2027 D Sept. 25, 2025, 4:54 p.m. OK Java 21 TESTS 10 280 409600
340510049 optimistic_Euler D Sept. 25, 2025, 5:06 p.m. OK Java 21 TESTS 10 280 512000
340503920 Rishabh_Sengar1 D Sept. 25, 2025, 4:45 p.m. OK Java 21 TESTS 10 280 614400
340548017 abhi_theq D Sept. 26, 2025, 1:44 a.m. OK Java 8 TESTS 11 140 0
340560888 TejashRamdharani D Sept. 26, 2025, 4:48 a.m. OK Java 8 TESTS 11 186 0
340543604 priyankahotkar_ D Sept. 26, 2025, 12:15 a.m. OK Java 8 TESTS 11 218 0
340532924 Shafat04 D Sept. 25, 2025, 8:49 p.m. OK Java 8 TESTS 11 234 3072000
340515400 Saumya1708 D Sept. 25, 2025, 5:45 p.m. OK Java 8 TESTS 10 249 0
340504116 Mohd_Ayaan_Hussain D Sept. 25, 2025, 4:46 p.m. OK Java 8 TESTS 10 265 0
340525224 SAI_GANGADHAR_0 D Sept. 25, 2025, 7:15 p.m. OK Java 8 TESTS 11 265 1536000
340519143 icecuber D Sept. 25, 2025, 6:17 p.m. OK Kotlin 2.2 TESTS 11 281 4096000
340519211 icecuber D Sept. 25, 2025, 6:18 p.m. OK Kotlin 2.2 TESTS 11 296 3993600
340530885 swseverance D Sept. 25, 2025, 8:21 p.m. OK Node.js TESTS 11 233 11059200
340529015 swseverance D Sept. 25, 2025, 7:58 p.m. OK Node.js TESTS 11 281 15872000
340532553 logankeede D Sept. 25, 2025, 8:43 p.m. OK PyPy 3 TESTS 11 171 9728000
340506069 vimaaan D Sept. 25, 2025, 4:48 p.m. OK PyPy 3 TESTS 10 327 9625600
340531721 sohamgupta.1515 D Sept. 25, 2025, 8:31 p.m. OK PyPy 3 TESTS 11 343 13312000
340505859 mikiyealem D Sept. 25, 2025, 4:48 p.m. OK PyPy 3 TESTS 10 374 10137600
340507674 shukir D Sept. 25, 2025, 4:53 p.m. OK PyPy 3 TESTS 10 375 9728000
340508846 jiangxian D Sept. 25, 2025, 4:59 p.m. OK PyPy 3 TESTS 10 436 9830400
340515668 TheOnlyJihed D Sept. 25, 2025, 5:47 p.m. OK PyPy 3 TESTS 10 499 9420800
340505529 sunny_day_ D Sept. 25, 2025, 4:48 p.m. OK PyPy 3 TESTS 10 499 9830400
340522676 realGrape D Sept. 25, 2025, 6:49 p.m. OK PyPy 3 TESTS 11 515 10956800
340550598 SoleProprietor D Sept. 26, 2025, 2:28 a.m. OK PyPy 3-64 TESTS 11 124 5734400
340538157 monocrap D Sept. 25, 2025, 10:02 p.m. OK PyPy 3-64 TESTS 11 139 4812800
340530322 mawo78 D Sept. 25, 2025, 8:13 p.m. OK PyPy 3-64 TESTS 11 155 8294400
340504428 salyamq D Sept. 25, 2025, 4:46 p.m. OK PyPy 3-64 TESTS 10 187 21606400
340513226 bekobek2006 D Sept. 25, 2025, 5:28 p.m. OK PyPy 3-64 TESTS 10 202 6451200
340520109 pusheen_1024 D Sept. 25, 2025, 6:26 p.m. OK PyPy 3-64 TESTS 11 202 15257600
340554697 fuyo1622 D Sept. 26, 2025, 3:27 a.m. OK PyPy 3-64 TESTS 11 203 7987200
340507286 Kaleab_Hailemeskel D Sept. 25, 2025, 4:52 p.m. OK PyPy 3-64 TESTS 10 203 9728000
340536731 HelloGoodbye D Sept. 25, 2025, 9:41 p.m. OK PyPy 3-64 TESTS 11 203 14540800
340504811 leite D Sept. 25, 2025, 4:47 p.m. OK PyPy 3-64 TESTS 10 218 5529600
340503791 mohdfaizan7 D Sept. 25, 2025, 4:45 p.m. OK Python 3 TESTS 10 109 9318400
340521695 shivamsinhagaya2020 D Sept. 25, 2025, 6:40 p.m. OK Python 3 TESTS 11 109 10444800
340506205 plastic_display D Sept. 25, 2025, 4:49 p.m. OK Python 3 TESTS 10 109 14540800
340523463 varun721 D Sept. 25, 2025, 6:57 p.m. OK Python 3 TESTS 11 124 9318400
340506485 voicesinmyhead D Sept. 25, 2025, 4:49 p.m. OK Python 3 TESTS 10 124 9318400
340532164 NoCodeNoLifeEz D Sept. 25, 2025, 8:37 p.m. OK Python 3 TESTS 11 125 10854400
340503369 shaikaddu2005 D Sept. 25, 2025, 4:44 p.m. OK Python 3 TESTS 10 140 5427200
340504005 JSrihari D Sept. 25, 2025, 4:45 p.m. OK Python 3 TESTS 10 140 9216000
340503454 smith_f D Sept. 25, 2025, 4:45 p.m. OK Python 3 TESTS 10 140 9728000
340513189 SnakeThug D Sept. 25, 2025, 5:28 p.m. OK Python 3 TESTS 10 140 13107200
340556192 0x81 D Sept. 26, 2025, 3:49 a.m. OK Rust 2024 TESTS 11 62 0

remove filters

Back to search problems