제출 #198213

#제출 시각아이디문제언어결과실행 시간메모리
198213parsa_mobed괄호 문자열 (CEOI16_match)C++14
37 / 100
2100 ms664 KiB
#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 10;
int a[N], n;
string s;

bool isval()
{
    vector <char> vec;
    for (int i = 0; i < n; i++) {
        if (a[i] == -1) {
            if (vec.empty() || vec.back() != s[i]) return 0;
            vec.pop_back();
        }
        if (a[i] == 1) vec.push_back(s[i]);
        if (a[i] == 0) {
            if (vec.size() && vec.back() == s[i]) vec.pop_back();
            else vec.push_back(s[i]);
        }
    }
    return vec.empty();
}
int main()
{
    cin >> s;
    n = s.size();
    if (!isval()) return cout << -1 << "\n", 0;
    for (int i = 0; i < n; i++) {
        a[i] = 1;
        if (!isval()) a[i] = -1;
    }
    for (int i = 0; i < n; i++) cout << (a[i] == 1 ? '(' : ')');
    cout << "\n";

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...