Submission #571862

# Submission time Handle Problem Language Result Execution time Memory
571862 2022-06-02T22:25:07 Z FerThugGato12500 Match (CEOI16_match) C++
37 / 100
2000 ms 660 KB
#include<bits/stdc++.h>
using namespace std;

string s;
int n;
bool poder(int ind, string A){

    stack<int> lst;
    int D = 0;

    for(int i = 0; i < n; i++){
        if(D<0) return false;
        if(i<=ind){
            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();

    string B = "";

    int j = 0;
    while(j<n){
     //       cout<<B<<" ";
        while(poder(j, B+'(')) { j++; B+='('; }
        B+=')';
        j++;
    }
    cout << (poder(n-1, B) ? B : "-1");
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Correct 5 ms 340 KB Output is correct
5 Correct 6 ms 340 KB Output is correct
6 Correct 10 ms 340 KB Output is correct
7 Correct 24 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Correct 5 ms 340 KB Output is correct
5 Correct 6 ms 340 KB Output is correct
6 Correct 10 ms 340 KB Output is correct
7 Correct 24 ms 348 KB Output is correct
8 Correct 288 ms 348 KB Output is correct
9 Correct 305 ms 580 KB Output is correct
10 Correct 286 ms 344 KB Output is correct
11 Correct 201 ms 340 KB Output is correct
12 Execution timed out 2073 ms 660 KB Time limit exceeded
13 Halted 0 ms 0 KB -