Submission #1117781

# Submission time Handle Problem Language Result Execution time Memory
1117781 2024-11-24T08:19:19 Z vjudge1 Match (CEOI16_match) C++17
0 / 100
2 ms 336 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define run  ios_base::sync_with_stdio(false);cin.tie(0);
 
#define ll long long
#define pll pair<ll, ll>
#define ull unsigned ll
#define ld double
#define endl "\n"
#define pb push_back
#define fi first
#define se second
 
#define pi acos(-1)
#define N 100007
#define minimum -9223372036854775807
#define maximum -minimum
#define mod 1000000007
 
using namespace std;
using namespace __gnu_pbds;
template <class t>
using ordered_set=tree<t, null_type,less_equal<t>, rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll gcd(ll a, ll b)
{
	if(b==0)
		return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b)
{
	return a/gcd(a, b)*b;
}

bool isprime(ll n)
{
	if(n==1)
		return 0;
	for(ll i=2; i*i<=n; i++)
	{
		if(n%i==0)
			return 0;
	}
	return 1;
}

ll binpow(ll a, ll b)
{
    a%=mod;
    ll res=1;
    while(b>0)
	{
        if(b%2==1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return res;
}

int main()
{
    run;
    freopen("match.in", "w", stdin);
    freopen("match.out", "r", stdout);
    string s;
    cin>>s;
    ll n=s.length(), b=0, a=0;
    for(ll i=0; i<n; i++)
    {
    	if(s[i]=='a')
    		a++;
    	else
    		b++;
	}
	char res[n];
	for(ll i=0; i<n; i++)
	{
		ll ii=i, cnt=1;
		while(ii<n && s[i]==s[i+1])
		{
			ii++;
			cnt++;
		}
		if(ii!=n)
		{
			if(cnt%2==1)
			{
				res[i]='(';
				ll j=i+1;
				for(ll k=j; k<ii; k+=2)
				{
					res[k]='(';
					res[k+1]=')';
				}
			}
			else
			{
				ll j=i;
				for(ll k=j; k<ii; k+=2)
				{
					res[k]='(';
					res[k+1]=')';
				}
			}
			i=ii;
		}
		else
		{
			cnt--;
			if(cnt%2==1)
			{
				ll j=i;
				for(ll k=j; k<n-1; k+=2)
				{
					res[k]='(';
					res[k+1]=')';
				}
				res[n-1]=')';
			}
			else
			{
				ll j=i;
				for(ll k=j; k<ii; k+=2)
				{
					res[k]='(';
					res[k+1]=')';
				}
			}
			break;
		}
	}
	string cvb="";
	for(ll i=0; i<n; i++)
	{
		cvb+=res[i];
	}
	ll p=0;
	bool bul=1;
	for(ll i=0; i<n; i++)
	{
		if(cvb[i]=='(')
			p++;
		else
			p--;
		if(p<0)
			bul=0;
	}
	if(p>0)
		bul=0;
	if(!bul)
		cout<<-1<<endl;
	else
		cout<<cvb<<endl;
}
// By Xanlar



// NUREDDIN <3 UZR ISTEYIREM PLS QEBUL ELE SENIN YERINDE OTURDUGUM UCUN

Compilation message

match.cpp: In function 'int main()':
match.cpp:69:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |     freopen("match.in", "w", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
match.cpp:70:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |     freopen("match.out", "r", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -