Codeforces Round 1019 (Div. 2)

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
2103 Codeforces Round 1019 (Div. 2) FINISHED False 7200 31159523 April 21, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 17611 ) B Binary Typewriter PROGRAMMING greedy math

You are given a binary string (s) of length (n) and a typewriter with two buttons: 0 and 1 . Initially, your finger is on the button 0 . You can do the following two operations: Press the button your finger is currently on. This will type out the character that is on the button. Move your finger to the other button. If your finger is on button 0 , move it to button 1 , and vice versa. The cost of a binary string is defined as the minimum number of operations needed to type the entire string. Before typing, you may reverse at most one substring(^{\text{∗}}) of (s). More formally, you can choose two indices (1\le l\le r\le n), and reverse the substring (s_{l\ldots r}), resulting in the new string (s_1s_2\ldots s_{l-1}s_rs_{r-1}\ldots s_ls_{r+1}\ldots s_n). Your task is to find the minimum possible cost among all strings obtainable by performing at most one substring reversal on (s). (^{\text{∗}})A string (a) is a substring of a string (b) if (a) can be obtained from (b) by the deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end. Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 10^4)). The description of the test cases follows. The first line of each test case contains a single integer (n) ((1\le n\le 2\cdot 10^5)) — the length of the binary string (s). The second line of each test case contains a binary string (s_1s_2\ldots s_n) ((s_i = \mathtt{0}) or (s_i = \mathtt{1})) — the characters of the binary string (s). It is guaranteed that the sum of (n) over all test cases does not exceed (2 \cdot 10^5). For each test case, output the minimum cost of string (s) after performing at most one substring reversal. In the first test case, we can choose not to reverse any substrings. We can do operation (1) three times to type 00

Tutorials

142149

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
316582471 doublethinker B April 21, 2025, 4:13 p.m. OK C# 10 TESTS 10 93 1331200
316638584 og.kostya B April 22, 2025, 5:53 a.m. OK C# 10 TESTS 10 93 2764800
316639384 chirag4520 B April 22, 2025, 6:04 a.m. OK C++17 (GCC 7-32) TESTS 10 46 0
316638949 TN07 B April 22, 2025, 5:58 a.m. OK C++17 (GCC 7-32) TESTS 10 46 0
316638593 nerdyLucifer B April 22, 2025, 5:54 a.m. OK C++17 (GCC 7-32) TESTS 10 46 0
316638203 Aletz B April 22, 2025, 5:48 a.m. OK C++17 (GCC 7-32) TESTS 10 46 0
316637474 Tusk_b03 B April 22, 2025, 5:38 a.m. OK C++17 (GCC 7-32) TESTS 10 46 0
316637412 Chenzq7 B April 22, 2025, 5:37 a.m. OK C++17 (GCC 7-32) TESTS 10 46 0
316637174 Arabian_dev B April 22, 2025, 5:34 a.m. OK C++17 (GCC 7-32) TESTS 10 46 0
316633467 graptea B April 22, 2025, 4:41 a.m. OK C++17 (GCC 7-32) TESTS 10 46 0
316633372 shengZzz B April 22, 2025, 4:40 a.m. OK C++17 (GCC 7-32) TESTS 10 46 0
316632123 ScaredQiu B April 22, 2025, 4:20 a.m. OK C++17 (GCC 7-32) TESTS 10 46 0
316597487 tin.le2 B April 21, 2025, 5:29 p.m. OK C++20 (GCC 13-64) TESTS 10 31 102400
316639299 Dr.KeK B April 22, 2025, 6:03 a.m. OK C++20 (GCC 13-64) TESTS 10 46 0
316638738 qiyuchen852 B April 22, 2025, 5:56 a.m. OK C++20 (GCC 13-64) TESTS 10 46 0
316636993 almizan B April 22, 2025, 5:31 a.m. OK C++20 (GCC 13-64) TESTS 10 46 0
316636336 Najmul_Huda_ B April 22, 2025, 5:22 a.m. OK C++20 (GCC 13-64) TESTS 10 46 0
316636260 Amia B April 22, 2025, 5:21 a.m. OK C++20 (GCC 13-64) TESTS 10 46 0
316635599 Baraah_Mohammed B April 22, 2025, 5:12 a.m. OK C++20 (GCC 13-64) TESTS 10 46 0
316635303 eklavya_kumar B April 22, 2025, 5:07 a.m. OK C++20 (GCC 13-64) TESTS 10 46 0
316634839 conqueror_of_jinwei B April 22, 2025, 5:01 a.m. OK C++20 (GCC 13-64) TESTS 10 46 0
316632882 hjxzq B April 22, 2025, 4:32 a.m. OK C++20 (GCC 13-64) TESTS 10 46 0
316635019 D1orn B April 22, 2025, 5:03 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 31 0
316604909 mogamal17 B April 21, 2025, 6:26 p.m. OK C++23 (GCC 14-64, msys2) TESTS 10 31 0
316639045 N0wh3r3R1ddl3 B April 22, 2025, 5:59 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 46 0
316639033 Zids B April 22, 2025, 5:59 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 46 0
316638860 Iqra B April 22, 2025, 5:57 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 46 0
316638607 nigonikhil B April 22, 2025, 5:54 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 46 0
316638040 sandipondas25 B April 22, 2025, 5:46 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 46 0
316636911 Kelecyrrr B April 22, 2025, 5:30 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 46 0
316636369 espacio B April 22, 2025, 5:23 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 46 0
316635870 alwaysBelieve B April 22, 2025, 5:16 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 46 0
316626243 tkddn5623 B April 22, 2025, 2:40 a.m. OK GNU C11 TESTS 10 46 307200
316585219 SiddharthShrimali B April 21, 2025, 4:20 p.m. OK GNU C11 TESTS 10 61 307200
316585682 Nishsethi B April 21, 2025, 4:21 p.m. OK GNU C11 TESTS 10 77 204800
316635482 ahmedafeef B April 22, 2025, 5:10 a.m. OK GNU C11 TESTS 10 77 307200
316586554 Ashraful00 B April 21, 2025, 4:23 p.m. OK GNU C11 TESTS 10 77 307200
316590502 alphaaaa_07 B April 21, 2025, 4:32 p.m. OK GNU C11 TESTS 10 92 307200
316586961 bindpankaj B April 21, 2025, 4:24 p.m. OK GNU C11 TESTS 10 93 307200
316584843 asdad123 B April 21, 2025, 4:19 p.m. OK GNU C11 TESTS 10 93 307200
316591079 phoenix_27_ B April 21, 2025, 4:33 p.m. OK GNU C11 TESTS 10 108 204800
316630907 ling_yue B April 22, 2025, 4:01 a.m. OK GNU C11 TESTS 10 108 409600
316580791 shiou B April 21, 2025, 4:09 p.m. OK Go TESTS 10 62 1536000
316585767 abhinav3001 B April 21, 2025, 4:21 p.m. OK Java 21 TESTS 10 217 819200
316603460 LordKRiS B April 21, 2025, 6:14 p.m. OK Java 21 TESTS 10 249 512000
316589944 Balu2907 B April 21, 2025, 4:31 p.m. OK Java 21 TESTS 10 249 614400
316628742 wyj123 B April 22, 2025, 3:24 a.m. OK Java 21 TESTS 10 249 819200
316585017 Gitansh_shekhar B April 21, 2025, 4:19 p.m. OK Java 21 TESTS 10 249 819200
316598588 vineet28sept B April 21, 2025, 5:37 p.m. OK Java 21 TESTS 10 264 512000
316600102 sharmanitin5114 B April 21, 2025, 5:48 p.m. OK Java 21 TESTS 10 265 512000
316628924 Sage_Eklavya B April 22, 2025, 3:27 a.m. OK Java 21 TESTS 10 280 512000
316591526 patelcodeforces B April 21, 2025, 4:34 p.m. OK Java 21 TESTS 10 280 1024000
316610848 hemanthkumar6843 B April 21, 2025, 7:25 p.m. OK Java 21 TESTS 10 281 307200
316598954 himan0610 B April 21, 2025, 5:40 p.m. OK Java 8 TESTS 10 140 0
316621857 Dduo B April 22, 2025, 1:09 a.m. OK Java 8 TESTS 10 171 0
316615857 abhayrajnegi0416 B April 21, 2025, 8:19 p.m. OK Java 8 TESTS 10 171 0
316590387 harsh_1806 B April 21, 2025, 4:32 p.m. OK Java 8 TESTS 10 171 0
316580269 Ronit0211 B April 21, 2025, 4:08 p.m. OK Java 8 TESTS 10 171 0
316606498 not_mohith B April 21, 2025, 6:40 p.m. OK Java 8 TESTS 10 187 0
316588748 FyReX_KING635 B April 21, 2025, 4:28 p.m. OK Java 8 TESTS 10 202 0
316582435 AnkitPandey21 B April 21, 2025, 4:13 p.m. OK Java 8 TESTS 10 202 0
316585174 ddbjiang B April 21, 2025, 4:20 p.m. OK Java 8 TESTS 10 218 2150400
316629570 adarsh400 B April 22, 2025, 3:39 a.m. OK Java 8 TESTS 10 233 0
316633167 shaskels B April 22, 2025, 4:37 a.m. OK Kotlin 1.9 TESTS 10 187 0
316632911 76ff7a B April 22, 2025, 4:32 a.m. OK Kotlin 1.9 TESTS 10 202 0
316590731 taruni2913 B April 21, 2025, 4:33 p.m. OK PyPy 2 TESTS 10 218 2252800
316597737 ManasJain B April 21, 2025, 5:31 p.m. OK PyPy 3 TESTS 10 140 5324800
316610701 dzh_pow B April 21, 2025, 7:23 p.m. OK PyPy 3 TESTS 10 265 6144000
316580358 Praysea B April 21, 2025, 4:08 p.m. OK PyPy 3 TESTS 10 281 9318400
316619770 kryoton_98 B April 22, 2025, 12:13 a.m. OK PyPy 3 TESTS 10 327 10240000
316608549 daveshub B April 21, 2025, 7 p.m. OK PyPy 3-64 TESTS 10 93 3686400
316625276 Emperor_Chen_Bai B April 22, 2025, 2:23 a.m. OK PyPy 3-64 TESTS 10 109 4505600
316579708 ssstormmid B April 21, 2025, 4:06 p.m. OK PyPy 3-64 TESTS 10 109 4608000
316604815 WaifuSlayer B April 21, 2025, 6:25 p.m. OK PyPy 3-64 TESTS 10 124 3686400
316596099 cold_beans B April 21, 2025, 5:19 p.m. OK PyPy 3-64 TESTS 10 124 4403200
316601485 ibraheemkureshi B April 21, 2025, 5:58 p.m. OK PyPy 3-64 TESTS 10 124 4505600
316590093 fermion5 B April 21, 2025, 4:31 p.m. OK PyPy 3-64 TESTS 10 124 6656000
316639001 EIR94326 B April 22, 2025, 5:59 a.m. OK PyPy 3-64 TESTS 10 124 12492800
316606941 Sanoy-si B April 21, 2025, 6:45 p.m. OK PyPy 3-64 TESTS 10 125 5017600
316583846 qianyyui B April 21, 2025, 4:16 p.m. OK PyPy 3-64 TESTS 10 140 5017600
316581786 AlgoRhythm1 B April 21, 2025, 4:11 p.m. OK Python 3 TESTS 10 93 716800
316616464 andrewliu10523 B April 21, 2025, 8:27 p.m. OK Python 3 TESTS 10 93 921600
316580364 michals B April 21, 2025, 4:08 p.m. OK Python 3 TESTS 10 108 2969600
316633526 tan.nekimdt B April 22, 2025, 4:42 a.m. OK Python 3 TESTS 10 109 1024000
316584040 841310284 B April 21, 2025, 4:17 p.m. OK Python 3 TESTS 10 109 1024000
316635531 kevindsilva39 B April 22, 2025, 5:11 a.m. OK Python 3 TESTS 10 124 819200
316608744 jaswanthkrishna2004 B April 21, 2025, 7:03 p.m. OK Python 3 TESTS 10 124 921600
316586299 harshith217 B April 21, 2025, 4:22 p.m. OK Python 3 TESTS 10 124 6144000
316606671 rajavarapu.avinash B April 21, 2025, 6:42 p.m. OK Python 3 TESTS 10 125 921600
316590234 Coder_Denji B April 21, 2025, 4:32 p.m. OK Python 3 TESTS 10 125 7270400
316587175 21312312ttt B April 21, 2025, 4:25 p.m. OK Rust 2021 TESTS 10 62 102400
316581639 CathySilverman B April 21, 2025, 4:11 p.m. OK Rust 2021 TESTS 10 77 102400

remove filters

Back to search problems