CSES - Aalto Competitive Programming 2024 - wk9 - Wed - Results
Submission details
Task:Bracket sequence
Sender:aalto2024j_006
Submission time:2024-11-06 16:26:25 +0200
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#60.00 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.01 sdetails
#11ACCEPTED0.00 sdetails
#12ACCEPTED0.00 sdetails
#130.00 sdetails
#140.00 sdetails
#15ACCEPTED0.00 sdetails
#160.00 sdetails
#17ACCEPTED0.00 sdetails
#18ACCEPTED0.00 sdetails
#19ACCEPTED0.00 sdetails
#20ACCEPTED0.00 sdetails
#21ACCEPTED0.00 sdetails
#22ACCEPTED0.00 sdetails
#230.00 sdetails
#240.00 sdetails
#25ACCEPTED0.00 sdetails
#260.00 sdetails
#270.00 sdetails
#28ACCEPTED0.00 sdetails
#29ACCEPTED0.00 sdetails
#30ACCEPTED0.00 sdetails
#310.00 sdetails
#32ACCEPTED0.00 sdetails
#33ACCEPTED0.00 sdetails
#340.00 sdetails
#350.00 sdetails
#36ACCEPTED0.00 sdetails
#37ACCEPTED0.00 sdetails
#380.00 sdetails
#39ACCEPTED0.00 sdetails
#40ACCEPTED0.00 sdetails
#410.00 sdetails
#42ACCEPTED0.00 sdetails
#430.00 sdetails
#440.00 sdetails
#450.00 sdetails
#46ACCEPTED0.00 sdetails
#47ACCEPTED0.00 sdetails
#480.00 sdetails
#49ACCEPTED0.00 sdetails
#50ACCEPTED0.00 sdetails
#51ACCEPTED0.00 sdetails
#52ACCEPTED0.00 sdetails
#530.00 sdetails
#540.00 sdetails
#550.00 sdetails
#56ACCEPTED0.00 sdetails
#570.01 sdetails
#58ACCEPTED0.01 sdetails
#59ACCEPTED0.00 sdetails
#60ACCEPTED0.00 sdetails
#610.01 sdetails
#62ACCEPTED0.00 sdetails
#630.01 sdetails
#640.00 sdetails
#650.01 sdetails

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++)
      |                     ~~^~~~~~~~~~

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 (s[i] == '(')
        {
            start.push_back(i);
        }
        else
        {
            if (start.empty())
                continue;
            
            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:

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: ACCEPTED

input
(()(

correct output
()

user output
()

Test 10

Verdict: ACCEPTED

input
)))))

correct output
-1

user output
-1

Test 11

Verdict: ACCEPTED

input
())(()

correct output
()

user output
()

Test 12

Verdict: ACCEPTED

input
))(()(

correct output
()

user output
()

Test 13

Verdict:

input
()(())

correct output
()(())

user output
(())

Test 14

Verdict:

input
()(())

correct output
()(())

user output
(())

Test 15

Verdict: ACCEPTED

input
()((((

correct output
()

user output
()

Test 16

Verdict:

input
(())(())((

correct output
(())(())

user output
(())

Test 17

Verdict: ACCEPTED

input
)))((()(((

correct output
()

user output
()

Test 18

Verdict: ACCEPTED

input
(()))(((((

correct output
(())

user output
(())

Test 19

Verdict: ACCEPTED

input
())(()())(

correct output
(()())

user output
(()())

Test 20

Verdict: ACCEPTED

input
))))))))))

correct output
-1

user output
-1

Test 21

Verdict: ACCEPTED

input
())(())(()

correct output
(())

user output
(())

Test 22

Verdict: ACCEPTED

input
)((())(()(

correct output
(())

user output
(())

Test 23

Verdict:

input
()(())()()

correct output
()(())()()

user output
(())

Test 24

Verdict:

input
()(())((()

correct output
()(())

user output
(())

Test 25

Verdict: ACCEPTED

input
()((((((((

correct output
()

user output
()

Test 26

Verdict:

input
((((((())))))))(((((((((()))))...

correct output
(((((())))))(((((((((()))))(((...

user output
(((((((((()))))((((((())))))))...

Test 27

Verdict:

input
)))((()((((((()()))(())(()(())...

correct output
((()((((((()()))(())(()(()))((...

user output
((()((((((()()))(())(()(()))((...

Test 28

Verdict: ACCEPTED

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:

input
())(())(()()()(()()()))((())((...

correct output
(())(()()()(()()()))((())(((((...

user output
((())(((((())))())((((()()()()...

Test 32

Verdict: ACCEPTED

input
(((((((((()))))))))((((((((())...

correct output
((((((((()))))))))

user output
((((((((()))))))))

Test 33

Verdict: ACCEPTED

input
()(())()()()(((((())))(((()())...

correct output
((((())))(((()()))((())(())())...

user output
((((())))(((()()))((())(())())...

Test 34

Verdict:

input
()(())((()))(((())))((((()))))...

correct output
()(())((()))(((())))((((()))))...

user output
((((((((()))))))))

Test 35

Verdict:

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:

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:

input
())(())(()()()(()()()))((())((...

correct output
(())(()()()(()()()))((())(((((...

user output
((())(((((())))())((((()()()()...

Test 42

Verdict: ACCEPTED

input
))))(((((((((((((())))))))))))...

correct output
((((((((((((()))))))))))))

user output
((((((((((((()))))))))))))

Test 43

Verdict:

input
()(())()()()(((((())))(((()())...

correct output
()()(((()())(()(((()(()(()(()(...

user output
(((()())(()(((()(()(()(()(()))...

Test 44

Verdict:

input
()(())((()))(((())))((((()))))...

correct output
()(())((()))(((())))((((()))))...

user output
((((((((((((()))))))))))))

Test 45

Verdict:

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:

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: ACCEPTED

input
())(())(()()()(()()()))((())((...

correct output
(((()((((((()(((((()(((()(((()...

user output
(((()((((((()(((((()(((()(((()...

Test 52

Verdict: ACCEPTED

input
(((((((())))))))))))))))))))))...

correct output
((((((((((((((((((((((((((((((...

user output
((((((((((((((((((((((((((((((...

Test 53

Verdict:

input
()(())()()()(((((())))(((()())...

correct output
()(())()()()(((((())))(((()())...

user output
(((((())))(((()()))((())(())()...

Test 54

Verdict:

input
()(())((()))(((())))((((()))))...

correct output
()(())((()))(((())))((((()))))...

user output
((((((((((((((((((((((((((((((...

Test 55

Verdict:

input
()(((((((()(((((((((()())())))...

correct output
(((())((())(())(((()(()()(()()...

user output
(((())((())(())(((()(()()(()()...

Test 56

Verdict: ACCEPTED

input
((((((((((((((((((((((((((((((...

correct output
((((((((((((((((((((((((((((((...

user output
((((((((((((((((((((((((((((((...

Test 57

Verdict:

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:

input
())(())(()()()(()()()))((())((...

correct output
(()(()()()(()())(())((((((()((...

user output
(()(()()()(()())(())((((((()((...

Test 62

Verdict: ACCEPTED

input
))))))))))))))))))))))))))))))...

correct output
((((((((((((((((((((((((((((((...

user output
((((((((((((((((((((((((((((((...

Test 63

Verdict:

input
()(())()()()(((((())))(((()())...

correct output
(()()((((())()()())())))((())(...

user output
((())(()())(()(()(()((()(((())...

Test 64

Verdict:

input
()(())((()))(((())))((((()))))...

correct output
()(())((()))(((())))((((()))))...

user output
((((((((((((((((((((((((((((((...

Test 65

Verdict:

input
()(((((((()(((((((((()())())))...

correct output
()(((((()()))()))()(())(((()((...

user output
(((((()()))()))()(())(((()(()(...