Submission #92364

# Submission time Handle Problem Language Result Execution time Memory
92364 2019-01-02T15:58:22 Z Pajaraja Match (CEOI16_match) C++17
10 / 100
2 ms 376 KB
#include <bits/stdc++.h>
#define MAXN 100007
using namespace std;
int lc[MAXN][26],l[26];
bool f;
string s;
void res(int l,int r)
{
	if(l>r) return;
	if(lc[r][s[l]-'a']==l) {f=true; return;}
	int t=lc[r][s[l]-'a']; 
	s[l]='('; s[t]=')';
	res(l+1,t-1); res(t+1,r);
}
int main()
{
	int n;
	cin>>s;
	n=s.size();
	for(int i=0;i<26;i++) l[i]=-1;
	for(int i=0;i<n;i++) {l[s[i]-'a']=i; for(int j=0;j<26;j++) lc[i][j]=l[j];}
	res(0,n-1);
	if(f) cout<<"-1";
	else cout<<s;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -