답안 #92364

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
92364 2019-01-02T15:58:22 Z Pajaraja 괄호 문자열 (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;
}
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -