Submission #476686

# Submission time Handle Problem Language Result Execution time Memory
476686 2021-09-28T07:42:18 Z TlenekWodoru Match (CEOI16_match) C++14
10 / 100
2000 ms 332 KB
#include <bits/stdc++.h>
using namespace std;
string odp;
vector<int>U;
string U2;
string A;
int otwarte=0;
bool sygnal=0;
void F(int v)
{
    if(otwarte>A.size()/2){return;}
    if(v==A.size())
    {
        if(U.size()==0)
        {
            odp=U2;
            sygnal=1;
        }
        return;
    }
    U.push_back(v);
    U2.push_back('(');
    otwarte++;
    F(v+1);
    if(sygnal==1){return;}
    otwarte--;
    U2.pop_back();
    U.pop_back();
    if(U.size()>0&&A[U[U.size()-1]]==A[v])
    {
        int kopia=U[U.size()-1];
        U2.push_back(')');
        U.pop_back();
        F(v+1);
        if(sygnal==1){return;}
        U.push_back(kopia);
        U2.pop_back();
    }
}
int main()
{ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>A;
    F(0);
    if(odp.size()==0){cout<<"-1"<<endl;}
    else{cout<<odp<<endl;}
    return 0;
}

Compilation message

match.cpp: In function 'void F(int)':
match.cpp:11:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     if(otwarte>A.size()/2){return;}
      |        ~~~~~~~^~~~~~~~~~~
match.cpp:12:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     if(v==A.size())
      |        ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Execution timed out 2076 ms 332 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Execution timed out 2076 ms 332 KB Time limit exceeded
5 Halted 0 ms 0 KB -