답안 #1117749

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1117749 2024-11-24T08:01:36 Z vjudge1 괄호 문자열 (CEOI16_match) C++17
10 / 100
2000 ms 3320 KB
// Telebe of adicto yani AzeTurk810
/*
    Author:             AzeTurk810
    Licance:            open source(only authors name must be in code)
    Begin               Time:11/23/2024 15:07
    Problem link:       https://basecamp.eolymp.com/az/problems/1533
*/
#include <bits/stdc++.h>


using namespace std;
using ll= long long;
using ull=unsigned long long;

# define vint vector<int>

# define endl '\n'
# define range(a,b,c) for(int i=a;i<b;i+=c)
# define arange(a,b,c) for(int i=a;i>b;i-=c)
# define bend(x) (x).begin(),(x).end()
# define pb push_back
# define eb emplace_back
# define fori(x) for(int i=0;i<x;i++)
# define forj(y) for(int j=0;j<y;j++)
# define forn(x,c) for(int i=0;i<n;i+=c)
# define forv(v) for(auto kullan : (v))
# define ff first
# define ss second
# define INF 1e9 + 7
# define printfprs(v) for(int alma = 0;alma<(v).size();alma++){cout<<(v)[alma].ff<< ' '<<(v)[alma].ss<<endl;};
# define int int64_t
# define hurryup ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

// mod(deysidirilmeli)  ________________________________________________________________________________________________________
# define mod 998244353

void ansyn(bool t)
{
	std::cout<<t?"Yes":"No";
}
/*int work(int prv , int cur , int m)
{
    m /= cur;
    int d = sqrt(prv) + 1;
    vint primes;
    vint powr;
    for(int i = 2; i<=d;i++)
    {
        if(prv % i ==0)
        {
            powr .eb(0);
            primes.pb(i);
            while(prv % i == 0)
            {
                prv /= i;
                ++powr.back();
            }
        }
    }
    if(prv > 1)
    {
        primes.pb(prv);
        powr.eb(1);
    }
    vint powr_of_current(powr.size(), 0);
    fori(powr.size())
    {
        while(cur % primes[i] == 0 )
        {
            cur /= primes[i];
            ++powr_of_current[i];
        }
    }
    vint n_divisbele;
    int ans =  m;
    fori(powr.size())
    {
        if(powr_of_current[i] < powr[i])
        {
            n_divisbele.eb(primes[i]);
        }
    }
    for(int ci= 1;ci < ( 1<<n_divisbele.size());ci++)
    {
        int juqli = 1;
        int pls_or_mns = 0;
        fori(n_divisbele.size())
        {
            if(((ci>> i) & 1))
            {
                pls_or_mns ^= 1;
                juqli *= n_divisbele[i];
            }
        }
        if(pls_or_mns )526842
        {
            ans -= m / juqli;
        }
        else
        {
            ans += m / juqli ;
        }
    }
    return ans % mod ;
}*/
int n;
string ansc;
string solve(string s,int index , string ans,int res,stack<char>last)
{
    int i = index;
    if(index >= n)
    {
        return (last.empty()?ans:"-1");
    }
    if(!last.empty())
    {

        last.push(s[i]);
        ansc = solve(s,index + 1,ans + '(',res,last);
        if(ansc == "-1" )
        {
            last.pop();
            //cout<<last.top()<<'|';
            if(last.top()!= s[i])
                return "-1";
            last.pop();
            return solve(s,index + 1 , ans + ')', res,last);
        }
        return ansc;
    }
    else
    {
        last.push(s[index]);
        //cout<<last.top()<<'/';
        return solve(s,index + 1,ans + '(',res,last);
    }
}

signed main()
{

    int t = 1;
    string s,ans = "";
    stack<char>last;
    /*
    last.push('3');
    last.push('5');
    cout<<last.top();
    5-----
    */
    while(t--)
    {

        cin>>s;
        n =s.size();
        if(n % 2 != 0)
        {
            cout<<-1<<endl;
        }
        else
        {
            cout<<solve(s,0,ans,0,last);
        }
    }

}

Compilation message

match.cpp: In function 'void ansyn(bool)':
match.cpp:39:15: warning: second operand of conditional expression has no effect [-Wunused-value]
   39 |  std::cout<<t?"Yes":"No";
      |               ^~~~~
match.cpp:39:21: warning: third operand of conditional expression has no effect [-Wunused-value]
   39 |  std::cout<<t?"Yes":"No";
      |                     ^~~~
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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 Execution timed out 2068 ms 3320 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Execution timed out 2068 ms 3320 KB Time limit exceeded
5 Halted 0 ms 0 KB -