Submission #1117596

# Submission time Handle Problem Language Result Execution time Memory
1117596 2024-11-24T06:33:12 Z AtabayRajabli Match (CEOI16_match) C++17
0 / 100
1 ms 336 KB
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define int long long
using namespace std;

const int sz = 1e5 + 5;
int n, f[26], o[26];
string s, t = "";

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> s;
    n = s.size();
    for(char c : s) f[c - 'a']++;

    bool ok = 0;
    for(int i = 0; i < 26; i++) ok |= (f[i] & 1);

    if(ok)
    {
        cout << -1;
        return 0;
    }

    for(int i = 0; i < n; i++)
    {
        int l = s[i] - 'a';
        if(f[l] > o[l])
        {
            t += '(';
            o[l]++;
            f[l]--;
        }
        else
        {
            t += ')';
            o[l]--;
            f[l]--;
        }
    }

    ok = 1;
    stack<int> st;
    for(int i = 0; i < n; i++)
    {
        if(t[i] == '(') st.push(i);
        else
        {
            ok &= s[st.top()] == s[i];
            st.pop();
        }
    }
    if(!ok) t = "-1";

    cout << t;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -