Task: | Bracket sequence |
Sender: | aalto2024j_006 |
Submission time: | 2024-11-06 16:36:33 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.01 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.01 s | details |
#7 | ACCEPTED | 0.00 s | details |
#8 | ACCEPTED | 0.00 s | details |
#9 | WRONG ANSWER | 0.00 s | details |
#10 | ACCEPTED | 0.00 s | details |
#11 | ACCEPTED | 0.00 s | details |
#12 | WRONG ANSWER | 0.00 s | details |
#13 | ACCEPTED | 0.00 s | details |
#14 | ACCEPTED | 0.00 s | details |
#15 | WRONG ANSWER | 0.01 s | details |
#16 | WRONG ANSWER | 0.00 s | details |
#17 | WRONG ANSWER | 0.00 s | details |
#18 | ACCEPTED | 0.00 s | details |
#19 | WRONG ANSWER | 0.00 s | details |
#20 | ACCEPTED | 0.00 s | details |
#21 | WRONG ANSWER | 0.00 s | details |
#22 | WRONG ANSWER | 0.00 s | details |
#23 | ACCEPTED | 0.00 s | details |
#24 | WRONG ANSWER | 0.00 s | details |
#25 | WRONG ANSWER | 0.00 s | details |
#26 | ACCEPTED | 0.00 s | details |
#27 | ACCEPTED | 0.00 s | details |
#28 | WRONG ANSWER | 0.00 s | details |
#29 | ACCEPTED | 0.00 s | details |
#30 | ACCEPTED | 0.00 s | details |
#31 | ACCEPTED | 0.00 s | details |
#32 | WRONG ANSWER | 0.00 s | details |
#33 | WRONG ANSWER | 0.00 s | details |
#34 | WRONG ANSWER | 0.00 s | details |
#35 | ACCEPTED | 0.00 s | details |
#36 | ACCEPTED | 0.00 s | details |
#37 | ACCEPTED | 0.00 s | details |
#38 | ACCEPTED | 0.00 s | details |
#39 | ACCEPTED | 0.00 s | details |
#40 | ACCEPTED | 0.00 s | details |
#41 | ACCEPTED | 0.00 s | details |
#42 | WRONG ANSWER | 0.00 s | details |
#43 | WRONG ANSWER | 0.00 s | details |
#44 | WRONG ANSWER | 0.00 s | details |
#45 | ACCEPTED | 0.00 s | details |
#46 | ACCEPTED | 0.00 s | details |
#47 | ACCEPTED | 0.00 s | details |
#48 | WRONG ANSWER | 0.00 s | details |
#49 | ACCEPTED | 0.00 s | details |
#50 | ACCEPTED | 0.00 s | details |
#51 | WRONG ANSWER | 0.00 s | details |
#52 | WRONG ANSWER | 0.00 s | details |
#53 | ACCEPTED | 0.00 s | details |
#54 | WRONG ANSWER | 0.00 s | details |
#55 | WRONG ANSWER | 0.00 s | details |
#56 | ACCEPTED | 0.00 s | details |
#57 | WRONG ANSWER | 0.01 s | details |
#58 | ACCEPTED | 0.01 s | details |
#59 | ACCEPTED | 0.00 s | details |
#60 | ACCEPTED | 0.00 s | details |
#61 | ACCEPTED | 0.01 s | details |
#62 | WRONG ANSWER | 0.00 s | details |
#63 | ACCEPTED | 0.01 s | details |
#64 | WRONG ANSWER | 0.00 s | details |
#65 | WRONG ANSWER | 0.01 s | details |
Compiler report
input/code.cpp: In function 'void solve()': input/code.cpp:30:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 30 | for (int i = 0; i < s.size(); i++) | ~~^~~~~~~~~~ input/code.cpp:32:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 32 | if (!start.empty() && i < s.size()-1 && s[i] == ')' && s[i+1] == '(') | ~~^~~~~~~~~~~~
Code
#include <iostream> #include <vector> #include <array> #include <string> #include <algorithm> #include <numeric> #include <unordered_map> #include <unordered_set> #include <queue> #include <climits> #include <cmath> #include <functional> #include <type_traits> #include <fstream> #include <bitset> #define int long long using namespace std; void solve() { string s; cin >> s; vector<int> start; start.reserve(s.size()); int maxLength = 0; int maxIdx = -1; for (int i = 0; i < s.size(); i++) { if (!start.empty() && i < s.size()-1 && s[i] == ')' && s[i+1] == '(') { i++; continue; } if (s[i] == '(') { start.push_back(i); } else { if (start.empty()) continue; /* if (start.back() == maxIdx + maxLength + 1) { maxLength += i - start.back() + 1; } */ if (i - start.back() > maxLength) { maxLength = i - start.back(); maxIdx = start.back(); } start.pop_back(); } } if (maxIdx == -1) cout << -1; else cout << s.substr(maxIdx, maxLength+1); } signed main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; //ifstream f("testcase.txt"); //cin.rdbuf(f.rdbuf()); for (int i = 0; i < t; i++) solve(); return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
( |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 2
Verdict: ACCEPTED
input |
---|
)) |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 3
Verdict: ACCEPTED
input |
---|
(( |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 4
Verdict: ACCEPTED
input |
---|
() |
correct output |
---|
() |
user output |
---|
() |
Test 5
Verdict: ACCEPTED
input |
---|
(() |
correct output |
---|
() |
user output |
---|
() |
Test 6
Verdict: ACCEPTED
input |
---|
()() |
correct output |
---|
()() |
user output |
---|
()() |
Test 7
Verdict: ACCEPTED
input |
---|
)))) |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 8
Verdict: ACCEPTED
input |
---|
())( |
correct output |
---|
() |
user output |
---|
() |
Test 9
Verdict: WRONG ANSWER
input |
---|
(()( |
correct output |
---|
() |
user output |
---|
-1 |
Test 10
Verdict: ACCEPTED
input |
---|
))))) |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 11
Verdict: ACCEPTED
input |
---|
())(() |
correct output |
---|
() |
user output |
---|
() |
Test 12
Verdict: WRONG ANSWER
input |
---|
))(()( |
correct output |
---|
() |
user output |
---|
-1 |
Test 13
Verdict: ACCEPTED
input |
---|
()(()) |
correct output |
---|
()(()) |
user output |
---|
()(()) |
Test 14
Verdict: ACCEPTED
input |
---|
()(()) |
correct output |
---|
()(()) |
user output |
---|
()(()) |
Test 15
Verdict: WRONG ANSWER
input |
---|
()(((( |
correct output |
---|
() |
user output |
---|
-1 |
Test 16
Verdict: WRONG ANSWER
input |
---|
(())(())(( |
correct output |
---|
(())(()) |
user output |
---|
() |
Test 17
Verdict: WRONG ANSWER
input |
---|
)))((()((( |
correct output |
---|
() |
user output |
---|
-1 |
Test 18
Verdict: ACCEPTED
input |
---|
(()))((((( |
correct output |
---|
(()) |
user output |
---|
(()) |
Test 19
Verdict: WRONG ANSWER
input |
---|
())(()())( |
correct output |
---|
(()()) |
user output |
---|
()() |
Test 20
Verdict: ACCEPTED
input |
---|
)))))))))) |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 21
Verdict: WRONG ANSWER
input |
---|
())(())(() |
correct output |
---|
(()) |
user output |
---|
() |
Test 22
Verdict: WRONG ANSWER
input |
---|
)((())(()( |
correct output |
---|
(()) |
user output |
---|
() |
Test 23
Verdict: ACCEPTED
input |
---|
()(())()() |
correct output |
---|
()(())()() |
user output |
---|
()(())()() |
Test 24
Verdict: WRONG ANSWER
input |
---|
()(())((() |
correct output |
---|
()(()) |
user output |
---|
() |
Test 25
Verdict: WRONG ANSWER
input |
---|
()(((((((( |
correct output |
---|
() |
user output |
---|
-1 |
Test 26
Verdict: ACCEPTED
input |
---|
((((((())))))))(((((((((()))))... |
correct output |
---|
(((((())))))(((((((((()))))(((... |
user output |
---|
(((((())))))(((((((((()))))(((... |
Test 27
Verdict: ACCEPTED
input |
---|
)))((()((((((()()))(())(()(())... |
correct output |
---|
((()((((((()()))(())(()(()))((... |
user output |
---|
((()((((((()()))(())(()(()))((... |
Test 28
Verdict: WRONG ANSWER
input |
---|
(()))((((((())(((()))))(())())... |
correct output |
---|
(((())((()()(((((())()))())))(... |
user output |
---|
((())((()()(((((())()))())))((... |
Test 29
Verdict: ACCEPTED
input |
---|
())))))))(((((((((())))(()))))... |
correct output |
---|
(((((((((())))(())))))((((((()... |
user output |
---|
(((((((((())))(())))))((((((()... |
Test 30
Verdict: ACCEPTED
input |
---|
))))))))))))))))))))))))))))))... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 31
Verdict: ACCEPTED
input |
---|
())(())(()()()(()()()))((())((... |
correct output |
---|
(())(()()()(()()()))((())(((((... |
user output |
---|
(())(()()()(()()()))((())(((((... |
Test 32
Verdict: WRONG ANSWER
input |
---|
(((((((((()))))))))((((((((())... |
correct output |
---|
((((((((())))))))) |
user output |
---|
(((((((()))))))) |
Test 33
Verdict: WRONG ANSWER
input |
---|
()(())()()()(((((())))(((()())... |
correct output |
---|
((((())))(((()()))((())(())())... |
user output |
---|
(((())))(((()()))((())(())())(... |
Test 34
Verdict: WRONG ANSWER
input |
---|
()(())((()))(((())))((((()))))... |
correct output |
---|
()(())((()))(((())))((((()))))... |
user output |
---|
(((((((()))))))) |
Test 35
Verdict: ACCEPTED
input |
---|
()(((((((()(((((((((()())())))... |
correct output |
---|
()(((((((()(((((((((()())())))... |
user output |
---|
()(((((((()(((((((((()())())))... |
Test 36
Verdict: ACCEPTED
input |
---|
((((((((((((())))))))))))))))(... |
correct output |
---|
((((((((((((((()))))))))))))((... |
user output |
---|
((((((((((((((()))))))))))))((... |
Test 37
Verdict: ACCEPTED
input |
---|
)))((()((((((()()))(())(()(())... |
correct output |
---|
((()((((()(()((()(())()((()())... |
user output |
---|
((()((((()(()((()(())()((()())... |
Test 38
Verdict: ACCEPTED
input |
---|
(()))((((((())(((()))))(())())... |
correct output |
---|
((((((())(((()))))(())())())((... |
user output |
---|
((((((())(((()))))(())())())((... |
Test 39
Verdict: ACCEPTED
input |
---|
(()))))))))))))))(((((((((((((... |
correct output |
---|
(((((((((((((((((()))))))((())... |
user output |
---|
(((((((((((((((((()))))))((())... |
Test 40
Verdict: ACCEPTED
input |
---|
))))))))))))))))))))))))))))))... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 41
Verdict: ACCEPTED
input |
---|
())(())(()()()(()()()))((())((... |
correct output |
---|
(())(()()()(()()()))((())(((((... |
user output |
---|
(())(()()()(()()()))((())(((((... |
Test 42
Verdict: WRONG ANSWER
input |
---|
))))(((((((((((((())))))))))))... |
correct output |
---|
((((((((((((())))))))))))) |
user output |
---|
(((((((((((()))))))))))) |
Test 43
Verdict: WRONG ANSWER
input |
---|
()(())()()()(((((())))(((()())... |
correct output |
---|
()()(((()())(()(((()(()(()(()(... |
user output |
---|
((()())(()(((()(()(()(()(()))(... |
Test 44
Verdict: WRONG ANSWER
input |
---|
()(())((()))(((())))((((()))))... |
correct output |
---|
()(())((()))(((())))((((()))))... |
user output |
---|
(((((((((((()))))))))))) |
Test 45
Verdict: ACCEPTED
input |
---|
()(((((((()(((((((((()())())))... |
correct output |
---|
()(((((((()(((((((((()())())))... |
user output |
---|
()(((((((()(((((((((()())())))... |
Test 46
Verdict: ACCEPTED
input |
---|
((((((((((((((((((((((((((((((... |
correct output |
---|
((((((((((((((((((((((((((((((... |
user output |
---|
((((((((((((((((((((((((((((((... |
Test 47
Verdict: ACCEPTED
input |
---|
)))((()((((((()()))(())(()(())... |
correct output |
---|
(((())()((()))()())((((((()(()... |
user output |
---|
(((())()((()))()())((((((()(()... |
Test 48
Verdict: WRONG ANSWER
input |
---|
(()))((((((())(((()))))(())())... |
correct output |
---|
((()))(()()((()()((((()()()(()... |
user output |
---|
()()((()()((((()()()(())((()((... |
Test 49
Verdict: ACCEPTED
input |
---|
(((((((())))))))))))))))))))))... |
correct output |
---|
((((((((((((((((((((((((((((((... |
user output |
---|
((((((((((((((((((((((((((((((... |
Test 50
Verdict: ACCEPTED
input |
---|
))))))))))))))))))))))))))))))... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 51
Verdict: WRONG ANSWER
input |
---|
())(())(()()()(()()()))((())((... |
correct output |
---|
(((()((((((()(((((()(((()(((()... |
user output |
---|
((()((((((()(((((()(((()(((()(... |
Test 52
Verdict: WRONG ANSWER
input |
---|
(((((((())))))))))))))))))))))... |
correct output |
---|
((((((((((((((((((((((((((((((... |
user output |
---|
((((((((((((((((((((((((((((()... |
Test 53
Verdict: ACCEPTED
input |
---|
()(())()()()(((((())))(((()())... |
correct output |
---|
()(())()()()(((((())))(((()())... |
user output |
---|
()(())()()()(((((())))(((()())... |
Test 54
Verdict: WRONG ANSWER
input |
---|
()(())((()))(((())))((((()))))... |
correct output |
---|
()(())((()))(((())))((((()))))... |
user output |
---|
((((((((((((((((((((((((((((((... |
Test 55
Verdict: WRONG ANSWER
input |
---|
()(((((((()(((((((((()())())))... |
correct output |
---|
(((())((())(())(((()(()()(()()... |
user output |
---|
((())((())(())(((()(()()(()())... |
Test 56
Verdict: ACCEPTED
input |
---|
((((((((((((((((((((((((((((((... |
correct output |
---|
((((((((((((((((((((((((((((((... |
user output |
---|
((((((((((((((((((((((((((((((... |
Test 57
Verdict: WRONG ANSWER
input |
---|
)))((()((((((()()))(())(()(())... |
correct output |
---|
(((()))(())(())(((((()())()(()... |
user output |
---|
((()))(())(())(((((()())()(())... |
Test 58
Verdict: ACCEPTED
input |
---|
(()))((((((())(((()))))(())())... |
correct output |
---|
(()()(()((()(((()(((()()()()((... |
user output |
---|
(()()(()((()(((()(((()()()()((... |
Test 59
Verdict: ACCEPTED
input |
---|
((((((((((((((((((((((((((((((... |
correct output |
---|
((((((((((((((((((((((((((((((... |
user output |
---|
((((((((((((((((((((((((((((((... |
Test 60
Verdict: ACCEPTED
input |
---|
))))))))))))))))))))))))))))))... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 61
Verdict: ACCEPTED
input |
---|
())(())(()()()(()()()))((())((... |
correct output |
---|
(()(()()()(()())(())((((((()((... |
user output |
---|
(()(()()()(()())(())((((((()((... |
Test 62
Verdict: WRONG ANSWER
input |
---|
))))))))))))))))))))))))))))))... |
correct output |
---|
((((((((((((((((((((((((((((((... |
user output |
---|
((((((((((((((((((((((((((((((... |
Test 63
Verdict: ACCEPTED
input |
---|
()(())()()()(((((())))(((()())... |
correct output |
---|
(()()((((())()()())())))((())(... |
user output |
---|
(()()((((())()()())())))((())(... |
Test 64
Verdict: WRONG ANSWER
input |
---|
()(())((()))(((())))((((()))))... |
correct output |
---|
()(())((()))(((())))((((()))))... |
user output |
---|
((((((((((((((((((((((((((((((... |
Test 65
Verdict: WRONG ANSWER
input |
---|
()(((((((()(((((((((()())())))... |
correct output |
---|
()(((((()()))()))()(())(((()((... |
user output |
---|
((((()()))()))()(())(((()(()((... |