# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
571863 | FerThugGato12500 | Match (CEOI16_match) | C++17 | 2089 ms | 852 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, B = "";
int n;
bool poder(string A){
stack<int> lst;
int D = 0;
for(int i = 0; i < n; i++){
if(D<0) return false;
if(i<A.size()){
if(A[i]=='('){ lst.push(i); D++; }
else{
if(!lst.size() || s[lst.top()]!=s[i]) return false;
lst.pop();
D--;
}
continue;
}
if(!lst.size() || s[lst.top()]!=s[i] ){
lst.push(i);
D++;
}else{
lst.pop();
D--;
}
}
return (D==0);
}
int main(){
cin>>s;
n = s.size();
int j = 0;
while(j<n){
int ini = 0, fin = n-j;
while(ini + 1 < fin){
int mit = (ini + fin) / 2;
string c = ""; for(int i = 0; i < mit; i++) c+='(';
if(poder(B + c)){
ini = mit;
}else{
fin = mit-1;
}
}
string c = ""; for(int i = 0; i < fin; i++) c+='(';
if(poder(B + c)) ini = fin;
for(int i = 0; i < ini; i++) B+='(';
B+=')';
j += ini+1;
}
cout << (poder(B) ? B : "-1");
return 0;
}
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... |