이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
string s;
int n;
bool check(string &curr, int pos){
if(curr == "" && pos == n)
return true;
if(curr.size() > (n - pos))
return false;
if(curr != "" && curr.back() == s[pos]){
curr.pop_back();
bool answer = check(curr, pos + 1);
curr += s[pos];
return answer;
}
curr += s[pos];
bool answer = check(curr, pos + 1);
curr.pop_back();
return answer;
}
void solve(string &answer, int pos){
if(answer == "" && pos == n)
return;
answer += s[pos];
if(check(answer, pos + 1)){
solve(answer, pos + 1);
answer += "(";
return;
}
answer.pop_back();
if(answer != "" && answer.back() == s[pos]){
answer.pop_back();
solve(answer, pos + 1);
answer += ")";
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> s;
n = s.size();
string answer = "";
if(!check(answer, 0)){
cout << "-1\n";
return 0;
}
solve(answer, 0);
reverse(answer.begin(), answer.end());
cout << answer << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
match.cpp: In function 'bool check(std::__cxx11::string&, int)':
match.cpp:11:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(curr.size() > (n - pos))
~~~~~~~~~~~~^~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |