Codeforces Round 1051 (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
2143 Codeforces Round 1051 (Div. 2) FINISHED False 7200 18285923 Sept. 17, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 1878 ) E Make Good PROGRAMMING constructive algorithms math strings

You are given a bracket string (s) of length (n). You can apply the following operations arbitrary number of times (possibly, zero) and in any order: Choose an index (1 \leq i < |s|) such that (s_i = s_{i+1} = (), and replace both (s_i) and (s_{i+1}) with ()). Choose an index (1 \leq i < |s|) such that (s_i = s_{i+1} = )), and replace both (s_i) and (s_{i+1}) with ((). Find a regular bracket sequence(^{\text{∗}}) (t) which can be obtained from (s) by applying the operations described above, or print (-1) if there is no such (t). (^{\text{∗}})A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example: the bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)") ; the bracket sequences ")(" , "(" and ")" are not. 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 contains one integer (n) ((1 \leq n \leq 2 \cdot 10^5)) — the length of the string. The second line contains a single string (s) — a sequence of the characters ( and ) of length (n). It is guaranteed that the sum of (n) over all test cases does not exceed (2 \cdot 10^5). For each test case output a regular bracket string (t) which can be obtained from (s) or print (-1) if there is no such (t). In the first testcase, the string "()()" is already a regular bracket sequence. No changes needed. In the second and third testcases it's impossible to reach a regular bracket string from (s). In the fourth testcase we can do the following: "))))))))" (\xrightarrow{i = 1}) "(())))))" "(())))))" (\xrightarrow{i = 5}) "(())(())" .

Tutorials

Codeforces Round 1051 (Div. 2) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
339178525 Teja-Smart E Sept. 17, 2025, 8:18 p.m. OK C++17 (GCC 7-32) TESTS 13 46 0
339171505 pradeepsingh271220 E Sept. 17, 2025, 6:47 p.m. OK C++17 (GCC 7-32) TESTS 13 46 0
339155206 Dindin E Sept. 17, 2025, 4:32 p.m. OK C++17 (GCC 7-32) TESTS 13 46 0
339151242 yaminijayameghana2004 E Sept. 17, 2025, 4:22 p.m. OK C++17 (GCC 7-32) TESTS 13 46 0
339148500 samkim21 E Sept. 17, 2025, 4:14 p.m. OK C++17 (GCC 7-32) TESTS 13 46 0
339199908 ywjylx E Sept. 18, 2025, 3:38 a.m. OK C++17 (GCC 7-32) TESTS 13 46 102400
339196091 killera E Sept. 18, 2025, 2:47 a.m. OK C++17 (GCC 7-32) TESTS 13 46 409600
339162573 Splashing E Sept. 17, 2025, 5:36 p.m. OK C++17 (GCC 7-32) TESTS 13 46 409600
339200264 qjm E Sept. 18, 2025, 3:43 a.m. OK C++17 (GCC 7-32) TESTS 13 46 1228800
339184585 uacoder123 E Sept. 17, 2025, 10:32 p.m. OK C++17 (GCC 7-32) TESTS 13 61 0
339207039 sis_12 E Sept. 18, 2025, 5:34 a.m. OK C++20 (GCC 13-64) TESTS 13 46 0
339205600 lightcreeper E Sept. 18, 2025, 5:16 a.m. OK C++20 (GCC 13-64) TESTS 13 46 0
339202400 Kan_kiz E Sept. 18, 2025, 4:23 a.m. OK C++20 (GCC 13-64) TESTS 13 46 0
339200037 volcano_2025 E Sept. 18, 2025, 3:40 a.m. OK C++20 (GCC 13-64) TESTS 13 46 0
339198760 Galaxy_Ivan E Sept. 18, 2025, 3:21 a.m. OK C++20 (GCC 13-64) TESTS 13 46 0
339197617 rt3 E Sept. 18, 2025, 3:07 a.m. OK C++20 (GCC 13-64) TESTS 13 46 0
339194167 fugazi_zeitgeist E Sept. 18, 2025, 2:20 a.m. OK C++20 (GCC 13-64) TESTS 13 46 0
339193999 TRfirst E Sept. 18, 2025, 2:17 a.m. OK C++20 (GCC 13-64) TESTS 13 46 0
339193192 pheonix_2002 E Sept. 18, 2025, 2:01 a.m. OK C++20 (GCC 13-64) TESTS 13 46 0
339192047 Love_Elaina E Sept. 18, 2025, 1:43 a.m. OK C++20 (GCC 13-64) TESTS 13 46 0
339209617 2949767807qwer E Sept. 18, 2025, 6:04 a.m. OK C++23 (GCC 14-64, msys2) TESTS 13 46 0
339206907 GentleYue E Sept. 18, 2025, 5:33 a.m. OK C++23 (GCC 14-64, msys2) TESTS 13 46 0
339206412 utshab1618 E Sept. 18, 2025, 5:27 a.m. OK C++23 (GCC 14-64, msys2) TESTS 13 46 0
339205884 czBene E Sept. 18, 2025, 5:20 a.m. OK C++23 (GCC 14-64, msys2) TESTS 13 46 0
339204387 advaitam E Sept. 18, 2025, 4:57 a.m. OK C++23 (GCC 14-64, msys2) TESTS 13 46 0
339202891 hanmx E Sept. 18, 2025, 4:31 a.m. OK C++23 (GCC 14-64, msys2) TESTS 13 46 0
339200497 JahonaliX E Sept. 18, 2025, 3:47 a.m. OK C++23 (GCC 14-64, msys2) TESTS 13 46 0
339200287 JahonaliX E Sept. 18, 2025, 3:44 a.m. OK C++23 (GCC 14-64, msys2) TESTS 13 46 0
339199664 DarksideForChen E Sept. 18, 2025, 3:34 a.m. OK C++23 (GCC 14-64, msys2) TESTS 13 46 0
339199192 fengxiabcd E Sept. 18, 2025, 3:27 a.m. OK C++23 (GCC 14-64, msys2) TESTS 13 46 0
339169282 ICPCCode E Sept. 17, 2025, 6:26 p.m. OK GNU C11 TESTS 13 390 307200
339155996 Supergene E Sept. 17, 2025, 4:34 p.m. OK Go TESTS 13 62 2252800
339149076 deepanshu_zen08 E Sept. 17, 2025, 4:16 p.m. OK Java 21 TESTS 13 249 716800
339150523 vellacoder E Sept. 17, 2025, 4:20 p.m. OK Java 21 TESTS 13 249 1228800
339149961 22BCS_KRG_IOT-3 E Sept. 17, 2025, 4:19 p.m. OK Java 21 TESTS 13 264 819200
339151092 animesh_288 E Sept. 17, 2025, 4:22 p.m. OK Java 21 TESTS 13 296 819200
339161254 Karma-X E Sept. 17, 2025, 5:28 p.m. OK Java 21 TESTS 13 343 1638400
339154911 d_c0d3r E Sept. 17, 2025, 4:32 p.m. OK Java 21 TESTS 13 343 2048000
339154238 Cyros E Sept. 17, 2025, 4:30 p.m. OK PyPy 2 TESTS 13 187 2252800
339150530 0.0 E Sept. 17, 2025, 4:20 p.m. OK PyPy 3 TESTS 13 171 9728000
339197700 kamio-misuzu E Sept. 18, 2025, 3:08 a.m. OK PyPy 3-64 TESTS 13 108 7065600
339151879 rahulsamant37 E Sept. 17, 2025, 4:24 p.m. OK PyPy 3-64 TESTS 13 124 6656000
339148969 DawnXTushar E Sept. 17, 2025, 4:16 p.m. OK PyPy 3-64 TESTS 13 140 7782400
339145917 kazumaa16 E Sept. 17, 2025, 4:07 p.m. OK PyPy 3-64 TESTS 13 140 16179200
339174065 siuhou E Sept. 17, 2025, 7:16 p.m. OK PyPy 3-64 TESTS 13 156 10035200
339151950 AxJx41 E Sept. 17, 2025, 4:24 p.m. OK PyPy 3-64 TESTS 13 171 4505600
339144984 chan120714 E Sept. 17, 2025, 4:05 p.m. OK PyPy 3-64 TESTS 13 171 6041600
339152055 SwarnimaSanwal E Sept. 17, 2025, 4:24 p.m. OK PyPy 3-64 TESTS 13 171 7680000
339194541 smilences E Sept. 18, 2025, 2:26 a.m. OK PyPy 3-64 TESTS 13 186 9318400
339151134 happybear21 E Sept. 17, 2025, 4:22 p.m. OK PyPy 3-64 TESTS 13 187 5427200
339144087 Easy_AC E Sept. 17, 2025, 4:02 p.m. OK Python 3 TESTS 13 109 921600
339173783 rush-228 E Sept. 17, 2025, 7:13 p.m. OK Python 3 TESTS 13 109 3891200
339154436 jai_gurudev E Sept. 17, 2025, 4:30 p.m. OK Python 3 TESTS 13 124 921600
339150916 hanyzead E Sept. 17, 2025, 4:21 p.m. OK Python 3 TESTS 13 156 3993600
339203399 kjpeng314 E Sept. 18, 2025, 4:41 a.m. OK Python 3 TESTS 13 202 3993600
339145375 Grinder_69 E Sept. 17, 2025, 4:06 p.m. OK Ruby 3 TESTS 13 1952 1126400
339152904 JKS_007 E Sept. 17, 2025, 4:27 p.m. OK Rust 2024 TESTS 13 61 102400

remove filters

Back to search problems