제출 #129981

#제출 시각아이디문제언어결과실행 시간메모리
129981TadijaSebez괄호 문자열 (CEOI16_match)C++11
100 / 100
20 ms11640 KiB
#include <bits/stdc++.h>
using namespace std;
const int N=100050;
char s[N],ans[N];
int pre[N][26];
bool ok=1;
void Solve(int l, int r)
{
	if(l>r) return;
	int m=pre[r][s[l]-'a'];
	if(m<=l){ ok=0;return;}
	ans[l]='(';
	ans[m]=')';
	Solve(l+1,m-1);
	Solve(m+1,r);
}
int main()
{
	int n;
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++) for(int j=0;j<26;j++)
	{
        if(j==s[i]-'a') pre[i][j]=i;
        else if(pre[i-1][s[i]-'a']>0) pre[i][j]=pre[pre[i-1][s[i]-'a']-1][j];
        else pre[i][j]=0;
	}
	Solve(1,n);
	if(ok) printf("%s",ans+1);
	else printf("-1\n");
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

match.cpp: In function 'int main()':
match.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",s+1);
  ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...