제출 #1293958

#제출 시각아이디문제언어결과실행 시간메모리
1293958eldaees131313괄호 문자열 (CEOI16_match)C++20
0 / 100
1 ms568 KiB
////////////////////////////// Author:eldaee, coder_viper!!!!!!!!!!!!!!!!!!!!!!!!11
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define int long long
#define str string
#define vec vector
#define dou double
#define ld long double
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define YES cout << "YES" << '\n'
#define Yes cout << "Yes" << '\n'
#define NO cout << "NO" << '\n'
#define No cout << "No" << '\n'
#define gcd __gcd
#define all(x) x.begin(),x.end()
#define eldaee ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/*


*/
using namespace std;

signed main()
{
    eldaee

    str s;
    cin >> s;
    int n = (int) s.size();
    vector<vector<int>> v(26);
    for (int i = 0; i < n; i++) {
        v[s[i] - 'a'].pb(i);
    }
    for (int i = 0; i < 26; i++) {
        if (v[i].size() % 2 != 0) {
            cout << -1 << "\n";
            return 0;
        }
    }
    str res(n, ' ');
    for (int c = 0; c < 26; c++) {
        auto& p = v[c];
        int k = (int) p.size();
        for (int i = 0; i < k / 2; i++) {
            int l = p[i];
            int r = p[k - 1 - i];
            res[l] = '(';
            res[r] = ')';
        }
    }
    cout << res << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...