답안 #608818

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
608818 2022-07-27T10:27:39 Z UncoolAnon 괄호 문자열 (CEOI16_match) C++14
10 / 100
0 ms 212 KB
#include <bits/stdc++.h> 
using namespace std; 
int ok=1; 
string answer,a;  
void solve(int l,int r){
	vector<int> occ(26); 
	int candidate=-1; 
	occ[a[l]-'a']++; 
	for(int i=l+1;i<=r;i++){
		occ[a[i]-'a']++; 
		bool yes=1; 
		for(int j=0;j<26;++j)yes&=(occ[j]%2==0);  
		if(yes&&a[i]==a[l]){
			candidate=i; 
		}
	}
	if(candidate==-1){
		ok=0; 
		return ; 
	}
	answer[l]='('; 
	answer[candidate]=')'; 
	if(l+1<=candidate-1) solve(l+1,candidate-1); 
	if( candidate+1<=r) solve(candidate+1,r); 
	return; 
}
int main(){
	cin>>a; 
	for(int i=0;i<a.size();++i) answer+='#'; 
	solve(0,a.size()-1); 
	if(!ok) cout<<-1; 
	else cout<<answer; 
}

Compilation message

match.cpp: In function 'int main()':
match.cpp:29:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for(int i=0;i<a.size();++i) answer+='#';
      |              ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -