Submission #223587

# Submission time Handle Problem Language Result Execution time Memory
223587 2020-04-15T14:16:23 Z MKopchev Match (CEOI16_match) C++14
37 / 100
2000 ms 772 KB
#include<bits/stdc++.h>
using namespace std;

const int nmax=1e5+42;

int n;
string inp;

string outp;

stack<int> active,mem;

bool check(int pos)
{
    while(pos<n)
    {
        if(active.size()==0)active.push(pos);
        else if(inp[active.top()]==inp[pos])active.pop();
        else active.push(pos);
        pos++;
    }
    return active.size()==0;
}
int main()
{
    cin>>inp;
    n=inp.size();

    if(check(0)==0)
    {
        printf("-1\n");
        return 0;
    }

    for(int i=0;i<n;i++)
    {
        mem=active;
        active.push(i);

        bool possible=check(i+1);

        active=mem;

        if(possible)
        {
            outp.push_back('(');
            active.push(i);
        }
        else
        {
            outp.push_back(')');
            active.pop();
        }
    }

    cout<<outp<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 12 ms 384 KB Output is correct
7 Correct 14 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 12 ms 384 KB Output is correct
7 Correct 14 ms 384 KB Output is correct
8 Correct 123 ms 384 KB Output is correct
9 Correct 148 ms 504 KB Output is correct
10 Correct 130 ms 384 KB Output is correct
11 Correct 117 ms 384 KB Output is correct
12 Execution timed out 2089 ms 772 KB Time limit exceeded
13 Halted 0 ms 0 KB -