Submission #1117733

# Submission time Handle Problem Language Result Execution time Memory
1117733 2024-11-24T07:53:44 Z vjudge1 Match (CEOI16_match) C++17
37 / 100
2000 ms 1012 KB
/*
#ifndef ONLINE_JUDGE
#include "AkbarKING.h" // aska geldi akbarking.h
#else
#define debug(...)
#define debugArr(...)
#define debugG(...)
#endif
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>

#define int long long
#define $AzH_TxdmN$ ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")

#define ep emplace_back
#define pb push_back
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using __indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using __indexed_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int sz = 3e5+9;
const int LOG = 63;
const int MOD = 1e9+7;
const int INF = 1e18;

string s;

bool check()
{
    if ((int)s.length() & 1)
    {
        cout<<"-1\n";
        return 0;
    }
    stack<int>st;
    for (int i = 0; i < (int)s.length(); ++i)
    {
        if (!st.empty() && s[st.top()] == s[i])
        {
            st.pop();
        }
        else
        {
            st.push(i);
        }
    }
    if (!st.empty())
    {
        cout<<"-1\n";
        return 0;
    }
    return 1;
}

void solve()
{
    cin>>s;
    if (check())
    {
        string res = "";
        stack<int>st;
        for (int i = 0; i < (int)s.length(); ++i)
        {
            stack<int>nwst = st;
            nwst.push(i);
            for (int j = i + 1; j < (int)s.length(); ++j)
            {
                if (!nwst.empty() && s[j] == s[nwst.top()])
                {
                    nwst.pop();
                }
                else
                {
                    nwst.push(j);
                }
            }
            if (nwst.empty())
            {
                res += "(";
                st.push(i);
            }
            else
            {
                res += ")";
                st.pop();
            }
        }
        cout<<res<<'\n';
    }
}

signed main()
{
    $AzH_TxdmN$
    //freopen("match.in", "r", stdin);
    //freopen("match.out", "w", stdout);
    int t = 1;
    //cin>>t;
    while (t--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 336 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 4 ms 336 KB Output is correct
7 Correct 6 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 336 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 4 ms 336 KB Output is correct
7 Correct 6 ms 336 KB Output is correct
8 Correct 45 ms 336 KB Output is correct
9 Correct 76 ms 496 KB Output is correct
10 Correct 63 ms 520 KB Output is correct
11 Correct 67 ms 504 KB Output is correct
12 Execution timed out 2041 ms 1012 KB Time limit exceeded
13 Halted 0 ms 0 KB -