답안 #126409

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
126409 2019-07-07T15:46:13 Z johutha 괄호 문자열 (CEOI16_match) C++14
37 / 100
2000 ms 1208 KB
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>

#define int int64_t

using namespace std;

struct brackseq
{
    string s;
    
    int n;

    bool poss(int fr, vector<int> stack)
    {
        stack.push_back(fr);
        fr++;
        for (int i = fr; i < n; i++)
        {
            if (stack.size() == 0 || s[i] != s[stack.back()])
            {
                stack.push_back(i);
            }
            else
            {
                stack.pop_back();
            }
        }
        return stack.size() == 0;
    }

    string calc()
    {
        vector<int> stack;
        string seq;
        
        for (int i = 0; i < n; i++)
        {
            if (poss(i, stack))
            {
                seq.push_back('(');
                stack.push_back(i);
            }
            else
            {
                if (stack.size() == 0) return "-1";
                seq.push_back(')');
                stack.pop_back();
            }
        }
        if (stack.size() > 0) return "-1";
        return seq;
    }
};

signed main()
{
    brackseq bs;
    cin >> bs.s;
    bs.n = bs.s.size();
    cout << bs.calc();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 9 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 9 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 9 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 9 ms 376 KB Output is correct
8 Correct 106 ms 504 KB Output is correct
9 Correct 130 ms 376 KB Output is correct
10 Correct 94 ms 476 KB Output is correct
11 Correct 93 ms 504 KB Output is correct
12 Execution timed out 2069 ms 1208 KB Time limit exceeded
13 Halted 0 ms 0 KB -