제출 #1293787

#제출 시각아이디문제언어결과실행 시간메모리
1293787zeyd123괄호 문자열 (CEOI16_match)C++20
0 / 100
1 ms568 KiB
#include <bits/stdc++.h>
using namespace std;

/*
      ---===ASCII help===---
     '0' -> 48     '9' -> 57
     'A' -> 65     'Z' -> 90
     'a' -> 97     'z' -> 122
*/

const long long mod = 1e9 + 7;

void solve() {
    string s; cin >> s;
    int n = s.size();
    if (n % 2 == 1) {
        cout << -1 << "\n";
        return;
    }
    string ans = string(n, '?');
    for (int i = 0; i < n - 1; ) {
        if (s[i] == s[i + 1]) {
            ans[i] = '('; ans[i + 1] = ')';
            i += 2;
        }
        else i++;
    }
    if (count(ans.begin(), ans.end(), '?') == n) {
        cout << -1 << "\n";
        return;
    }
    else {
        for (int i = 0; i < n / 2; i++) {
            if (s[i] == s[n - i - 1] && (ans[i] != '(' && ans[i] != ')') && (ans[n - i - 1] != '(' && ans[n - i - 1] != ')')) {
                ans[i] = '('; ans[n - i - 1] = ')';
            }
        }
        if (count(ans.begin(), ans.end(), '?') > 0) cout << -1 << "\n";
        else cout << ans << "\n";
    }
}

int main() {
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...