# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
236763 | Sorting | Match (CEOI16_match) | C++14 | 2041 ms | 512 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
string s;
int n;
bool solve(string &answer, int pos){
if(answer == "" && pos == n)
return true;
if(answer.size() > (n - pos))
return false;
answer += s[pos];
if(solve(answer, pos + 1)){
answer += "(";
return true;
}
answer.pop_back();
if(answer != "" && answer.back() == s[pos]){
answer.pop_back();
if(solve(answer, pos + 1)){
answer += ")";
return true;
}
answer += s[pos];
}
return false;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> s;
n = s.size();
string answer = "";
if(solve(answer, 0)){
reverse(answer.begin(), answer.end());
cout << answer << "\n";
}
else
cout << "-1\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |