Submission #476697

# Submission time Handle Problem Language Result Execution time Memory
476697 2021-09-28T08:52:52 Z wiktoria_bazan Match (CEOI16_match) C++14
0 / 100
0 ms 204 KB
#include <iostream>
#include <stack>
#include <algorithm>
#include <string>
using namespace std;

int n;
string s;
stack <int> S;

void task() {
    int sum = 0;
    string w = "";
    for (int i = 0; i < n; i++) {
        if (S.empty()) {
            sum++;
            w.insert(w.size(), "(");
            S.push(s[i]);
        }
        else {
            int v = S.top();
            if (v == s[i]) {
                sum--;
                S.pop();
                w.insert(w.size(), ")");
            }
            else {
                sum++;
                w.insert(w.size(), "(");
                S.push(s[i]);
            }
        }
    }
    if (sum != 0) cout << -1;
    else cout << w;
    return;
}

int main()
{
    cin >> s;
    n = s.size();
    task();
   
}


# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -