Submission #476184

# Submission time Handle Problem Language Result Execution time Memory
476184 2021-09-25T09:19:29 Z MohamedAhmed04 Match (CEOI16_match) C++14
Compilation error
0 ms 0 KB
abbaaaa#include <bits/stdc++.h>

using namespace std ;

const int MAX = 1e5 + 10 ;

int arr[MAX] ;
int n ;

string s ;
stack<char>st ;

int prv[MAX][26] ;

char ans[MAX] ;

void solve(int l , int r)
{
	if(l > r)
		return ;
	int idx = prv[r][s[l]-'a'] ;
	ans[l] = '(' , ans[idx] = ')' ;
	solve(l+1 , idx-1) , solve(idx+1 , r) ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>s ;
	n = s.size() ;
	s = '#' + s ;
	for(int i = 1 ; i <= n ; ++i)
	{
		if(st.size() && st.top() == s[i])
			st.pop() ;
		else
			st.push(s[i]) ; 
	}
	if(st.size())
		return cout<<-1<<"\n" , 0 ;
	for(int i = 1 ; i <= n ; ++i)
	{
		int x = prv[i-1][(s[i] - 'a')] ;
		for(int j = 0 ; j < 2 ; ++j)
		{
			if((s[i] - 'a') == j)
				prv[i][j] = i ;
			else if(x)
				prv[i][j] = prv[x-1][j] ;
		}
	}
	solve(1 , n) ;
	for(int i = 1 ; i <= n ; ++i)
		cout<<ans[i] ;
	cout<<"\n" ;
	return 0 ;
}		

Compilation message

match.cpp:1:8: error: stray '#' in program
    1 | abbaaaa#include <bits/stdc++.h>
      |        ^
match.cpp:1:1: error: 'abbaaaa' does not name a type
    1 | abbaaaa#include <bits/stdc++.h>
      | ^~~~~~~
match.cpp:10:1: error: 'string' does not name a type
   10 | string s ;
      | ^~~~~~
match.cpp:11:1: error: 'stack' does not name a type
   11 | stack<char>st ;
      | ^~~~~
match.cpp: In function 'void solve(int, int)':
match.cpp:21:19: error: 's' was not declared in this scope
   21 |  int idx = prv[r][s[l]-'a'] ;
      |                   ^
match.cpp: In function 'int main()':
match.cpp:28:2: error: 'ios_base' has not been declared
   28 |  ios_base::sync_with_stdio(0) ;
      |  ^~~~~~~~
match.cpp:29:2: error: 'cin' was not declared in this scope
   29 |  cin.tie(0) ;
      |  ^~~
match.cpp:30:7: error: 's' was not declared in this scope
   30 |  cin>>s ;
      |       ^
match.cpp:35:6: error: 'st' was not declared in this scope; did you mean 'std'?
   35 |   if(st.size() && st.top() == s[i])
      |      ^~
      |      std
match.cpp:40:5: error: 'st' was not declared in this scope; did you mean 'std'?
   40 |  if(st.size())
      |     ^~
      |     std
match.cpp:41:10: error: 'cout' was not declared in this scope
   41 |   return cout<<-1<<"\n" , 0 ;
      |          ^~~~
match.cpp:55:3: error: 'cout' was not declared in this scope
   55 |   cout<<ans[i] ;
      |   ^~~~
match.cpp:56:2: error: 'cout' was not declared in this scope
   56 |  cout<<"\n" ;
      |  ^~~~