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'A bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example, sequences "(())()", "()" and "(()(()))" are correct, while ")(", "(()" and "(()))(" are not. The teacher gave Dmitry 's class a very strange task -- she asked every student to come up with a sequence of arbitrary length, consisting only of opening and closing brackets. After that all the students took turns naming the sequences they had invented. When Dima 's turn came, he suddenly realized that all his classmates got the correct bracketed sequence, and whether he got the correct bracketed sequence, he did not know. Dima suspects now that he simply missed the word "correct" in the task statement, so now he wants to save the situation by modifying his sequence slightly. More precisely, he can the arbitrary number of times (possibly zero) perform the reorder operation. The reorder operation consists of choosing an arbitrary consecutive subsegment (substring) of the sequence and then reordering all the characters in it in an arbitrary way. Such operation takes l nanoseconds, where l is the length of the subsegment being reordered. It 's easy to see that reorder operation doesn 't change the number of opening and closing brackets. For example for "))((" he can choose the substring ")(" and do reorder ")()(" (this operation will take 2 nanoseconds). Since Dima will soon have to answer, he wants to make his sequence correct as fast as possible. Help him to do this, or determine that it 's impossible. The first line contains a single integer n ( 1 <= n <= 10^6 ) -- the length of Dima 's sequence. The second line contains string of length n , consisting of characters "(" and ")" only. Print a single integer -- the minimum number of nanoseconds to make the sequence correct or "-1" if it is impossible to do so. In the first example we can firstly reorder the segment from first to the f'... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
72630582 |
Gassa |
A |
March 7, 2020, 9:41 a.m. |
OK |
D |
TESTS |
79 |
61 |
4198400 |
|
|
72631886 |
physics0523 |
A |
March 7, 2020, 9:44 a.m. |
OK |
GNU C11 |
TESTS |
79 |
31 |
1024000 |
|
|
72661300 |
DeaphetS |
A |
March 7, 2020, 12:28 p.m. |
OK |
GNU C++11 |
TESTS |
79 |
31 |
0 |
|
|
72630964 |
Kewth |
A |
March 7, 2020, 9:42 a.m. |
OK |
GNU C++11 |
TESTS |
79 |
31 |
819200 |
|
|
72630214 |
ztc_dot |
A |
March 7, 2020, 9:41 a.m. |
OK |
GNU C++11 |
TESTS |
79 |
31 |
819200 |
|
|
72629754 |
huhaoo |
A |
March 7, 2020, 9:40 a.m. |
OK |
GNU C++11 |
TESTS |
79 |
31 |
819200 |
|
|
72632721 |
2016wudi |
A |
March 7, 2020, 9:46 a.m. |
OK |
GNU C++11 |
TESTS |
79 |
31 |
819200 |
|
|
72631249 |
C20193515_LYX |
A |
March 7, 2020, 9:43 a.m. |
OK |
GNU C++11 |
TESTS |
79 |
31 |
819200 |
|
|
72630988 |
command_block |
A |
March 7, 2020, 9:42 a.m. |
OK |
GNU C++11 |
TESTS |
79 |
31 |
819200 |
|
|
72630479 |
geneanlyz |
A |
March 7, 2020, 9:41 a.m. |
OK |
GNU C++11 |
TESTS |
79 |
31 |
921600 |
|
|
72633559 |
142857 |
A |
March 7, 2020, 9:48 a.m. |
OK |
GNU C++11 |
TESTS |
79 |
31 |
921600 |
|
|
72697372 |
WZYYN |
A |
March 8, 2020, 12:55 a.m. |
OK |
GNU C++11 |
TESTS |
79 |
31 |
1024000 |
|
|
72630668 |
TadijaSebez |
A |
March 7, 2020, 9:42 a.m. |
OK |
GNU C++14 |
TESTS |
79 |
31 |
1024000 |
|
|
72661675 |
iotang |
A |
March 7, 2020, 12:32 p.m. |
OK |
GNU C++14 |
TESTS |
79 |
31 |
1024000 |
|
|
72649505 |
pufanyi |
A |
March 7, 2020, 10:49 a.m. |
OK |
GNU C++14 |
TESTS |
79 |
31 |
1024000 |
|
|
72647587 |
tlwpdus |
A |
March 7, 2020, 10:40 a.m. |
OK |
GNU C++14 |
TESTS |
79 |
31 |
1024000 |
|
|
72639082 |
KisekiPurin2019 |
A |
March 7, 2020, 10:07 a.m. |
OK |
GNU C++14 |
TESTS |
79 |
31 |
1024000 |
|
|
72634159 |
kimoyami |
A |
March 7, 2020, 9:49 a.m. |
OK |
GNU C++14 |
TESTS |
79 |
31 |
1024000 |
|
|
72634018 |
aaaaajack |
A |
March 7, 2020, 9:49 a.m. |
OK |
GNU C++14 |
TESTS |
79 |
31 |
1024000 |
|
|
72631279 |
mateusz |
A |
March 7, 2020, 9:43 a.m. |
OK |
GNU C++14 |
TESTS |
79 |
31 |
1024000 |
|
|
72630936 |
JooooooooooDdae |
A |
March 7, 2020, 9:42 a.m. |
OK |
GNU C++14 |
TESTS |
79 |
31 |
1024000 |
|
|
72630442 |
Torta |
A |
March 7, 2020, 9:41 a.m. |
OK |
GNU C++14 |
TESTS |
79 |
31 |
1024000 |
|
|
72670378 |
R51234 |
A |
March 7, 2020, 2:39 p.m. |
OK |
GNU C++17 |
TESTS |
79 |
31 |
1024000 |
|
|
72698165 |
Son |
A |
March 8, 2020, 1:37 a.m. |
OK |
GNU C++17 |
TESTS |
79 |
31 |
1024000 |
|
|
72647150 |
Lucina |
A |
March 7, 2020, 10:38 a.m. |
OK |
GNU C++17 |
TESTS |
79 |
31 |
1024000 |
|
|
72634794 |
RedStone |
A |
March 7, 2020, 9:52 a.m. |
OK |
GNU C++17 |
TESTS |
79 |
31 |
1024000 |
|
|
72631111 |
BinGoo0o0o |
A |
March 7, 2020, 9:42 a.m. |
OK |
GNU C++17 |
TESTS |
79 |
31 |
1024000 |
|
|
72630370 |
SunshinePie |
A |
March 7, 2020, 9:41 a.m. |
OK |
GNU C++17 |
TESTS |
79 |
31 |
1024000 |
|
|
72630013 |
AcF-_-FcA |
A |
March 7, 2020, 9:41 a.m. |
OK |
GNU C++17 |
TESTS |
79 |
31 |
1024000 |
|
|
72669298 |
Sneakoscope |
A |
March 7, 2020, 2:22 p.m. |
OK |
GNU C++17 |
TESTS |
79 |
31 |
1024000 |
|
|
72630035 |
cxaphoenix |
A |
March 7, 2020, 9:41 a.m. |
OK |
GNU C++17 |
TESTS |
79 |
31 |
1126400 |
|
|
72635589 |
chenjb |
A |
March 7, 2020, 9:54 a.m. |
OK |
GNU C++17 |
TESTS |
79 |
31 |
1126400 |
|
|
72687701 |
Hemose |
A |
March 7, 2020, 7:35 p.m. |
OK |
Java 11 |
TESTS |
79 |
187 |
0 |
|
|
72685852 |
dash2199 |
A |
March 7, 2020, 6:58 p.m. |
OK |
Java 11 |
TESTS |
79 |
187 |
0 |
|
|
72629399 |
mikit |
A |
March 7, 2020, 9:40 a.m. |
OK |
Java 11 |
TESTS |
79 |
202 |
0 |
|
|
72629795 |
uwi |
A |
March 7, 2020, 9:40 a.m. |
OK |
Java 11 |
TESTS |
79 |
218 |
0 |
|
|
72629526 |
Musin |
A |
March 7, 2020, 9:40 a.m. |
OK |
Java 11 |
TESTS |
79 |
218 |
0 |
|
|
72632834 |
Arya_Erin |
A |
March 7, 2020, 9:46 a.m. |
OK |
Java 11 |
TESTS |
79 |
265 |
4608000 |
|
|
72665494 |
himanshua04 |
A |
March 7, 2020, 1:25 p.m. |
OK |
Java 11 |
TESTS |
79 |
296 |
2560000 |
|
|
72629545 |
Agnimandur |
A |
March 7, 2020, 9:40 a.m. |
OK |
Java 8 |
TESTS |
79 |
124 |
0 |
|
|
72686727 |
golions |
A |
March 7, 2020, 7:16 p.m. |
OK |
Java 8 |
TESTS |
79 |
140 |
0 |
|
|
72650008 |
DarLam |
A |
March 7, 2020, 10:51 a.m. |
OK |
Java 8 |
TESTS |
79 |
140 |
0 |
|
|
72632550 |
fetetriste |
A |
March 7, 2020, 9:45 a.m. |
OK |
Java 8 |
TESTS |
79 |
140 |
0 |
|
|
72629665 |
qwerty787788 |
A |
March 7, 2020, 9:40 a.m. |
OK |
Java 8 |
TESTS |
79 |
140 |
0 |
|
|
72629582 |
Taran_1407 |
A |
March 7, 2020, 9:40 a.m. |
OK |
Java 8 |
TESTS |
79 |
140 |
0 |
|
|
72631943 |
SecondThread |
A |
March 7, 2020, 9:44 a.m. |
OK |
Java 8 |
TESTS |
79 |
140 |
10035200 |
|
|
72630305 |
cwise |
A |
March 7, 2020, 9:41 a.m. |
OK |
Java 8 |
TESTS |
79 |
140 |
20684800 |
|
|
72691571 |
ijxjdjd |
A |
March 7, 2020, 9:11 p.m. |
OK |
Java 8 |
TESTS |
79 |
155 |
3379200 |
|
|
72635297 |
Sergey.Bankevich |
A |
March 7, 2020, 9:53 a.m. |
OK |
Kotlin |
TESTS |
79 |
171 |
0 |
|
|
72629820 |
darnley |
A |
March 7, 2020, 9:40 a.m. |
OK |
Kotlin |
TESTS |
79 |
218 |
0 |
|
|
72631554 |
Tlatoani |
A |
March 7, 2020, 9:43 a.m. |
OK |
Kotlin |
TESTS |
79 |
233 |
102400 |
|
|
72632199 |
LebronDurant |
A |
March 7, 2020, 9:45 a.m. |
OK |
MS C++ |
TESTS |
79 |
46 |
9011200 |
|
|
72633660 |
math957963 |
A |
March 7, 2020, 9:48 a.m. |
OK |
MS C++ |
TESTS |
79 |
62 |
9830400 |
|
|
72698749 |
dacc |
A |
March 8, 2020, 2:12 a.m. |
OK |
MS C++ |
TESTS |
79 |
124 |
1024000 |
|
|
72700176 |
joo6361 |
A |
March 8, 2020, 3:11 a.m. |
OK |
MS C++ 2017 |
TESTS |
79 |
46 |
1945600 |
|
|
72632793 |
AlexIlin |
A |
March 7, 2020, 9:46 a.m. |
OK |
MS C++ 2017 |
TESTS |
79 |
46 |
1945600 |
|
|
72630281 |
CrashMaster |
A |
March 7, 2020, 9:41 a.m. |
OK |
MS C++ 2017 |
TESTS |
79 |
46 |
1945600 |
|
|
72632050 |
vpike |
A |
March 7, 2020, 9:44 a.m. |
OK |
MS C++ 2017 |
TESTS |
79 |
46 |
2560000 |
|
|
72632167 |
pichulia |
A |
March 7, 2020, 9:44 a.m. |
OK |
MS C++ 2017 |
TESTS |
79 |
46 |
5017600 |
|
|
72633399 |
Alexandr_TS |
A |
March 7, 2020, 9:47 a.m. |
OK |
MS C++ 2017 |
TESTS |
79 |
46 |
9011200 |
|
|
72630113 |
Timonnable |
A |
March 7, 2020, 9:41 a.m. |
OK |
MS C++ 2017 |
TESTS |
79 |
46 |
9113600 |
|
|
72667232 |
GiveMeSomething |
A |
March 7, 2020, 1:52 p.m. |
OK |
MS C++ 2017 |
TESTS |
79 |
62 |
307200 |
|
|
72651931 |
gnomina007 |
A |
March 7, 2020, 11 a.m. |
OK |
MS C++ 2017 |
TESTS |
79 |
217 |
8294400 |
|
|
72629276 |
bcollet |
A |
March 7, 2020, 9:39 a.m. |
OK |
PyPy 2 |
TESTS |
79 |
171 |
5427200 |
|
|
72634012 |
satyamcse |
A |
March 7, 2020, 9:49 a.m. |
OK |
PyPy 2 |
TESTS |
79 |
217 |
14540800 |
|
|
72631429 |
chielo |
A |
March 7, 2020, 9:43 a.m. |
OK |
PyPy 3 |
TESTS |
79 |
233 |
6656000 |
|
|
72631348 |
fanfly |
A |
March 7, 2020, 9:43 a.m. |
OK |
PyPy 3 |
TESTS |
79 |
248 |
6553600 |
|
|
72632309 |
tamato |
A |
March 7, 2020, 9:45 a.m. |
OK |
PyPy 3 |
TESTS |
79 |
248 |
7884800 |
|
|
72632003 |
neterukun |
A |
March 7, 2020, 9:44 a.m. |
OK |
PyPy 3 |
TESTS |
79 |
264 |
7884800 |
|
|
72631842 |
titia |
A |
March 7, 2020, 9:44 a.m. |
OK |
PyPy 3 |
TESTS |
79 |
280 |
14028800 |
|
|
72694836 |
wider93 |
A |
March 7, 2020, 11:23 p.m. |
OK |
PyPy 3 |
TESTS |
79 |
342 |
7782400 |
|
|
72673597 |
under_score01 |
A |
March 7, 2020, 3:36 p.m. |
OK |
Python 2 |
TESTS |
79 |
623 |
2662400 |
|
|
72674227 |
karan124 |
A |
March 7, 2020, 3:47 p.m. |
OK |
Python 3 |
TESTS |
79 |
421 |
3174400 |
|
|
72679128 |
subhajitdas |
A |
March 7, 2020, 5:11 p.m. |
OK |
Python 3 |
TESTS |
79 |
452 |
6246400 |
|
|
72668231 |
Stephan_Sok |
A |
March 7, 2020, 2:05 p.m. |
OK |
Python 3 |
TESTS |
79 |
530 |
3379200 |
|
|
72694488 |
__B1ank__ |
A |
March 7, 2020, 11:05 p.m. |
OK |
Python 3 |
TESTS |
79 |
561 |
3584000 |
|
|
72630416 |
sansen |
A |
March 7, 2020, 9:41 a.m. |
OK |
Rust |
TESTS |
79 |
46 |
8089600 |
|
|
remove filters
Back to search problems