답안 #75099

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
75099 2018-09-08T10:30:27 Z Yehezkiel 괄호 문자열 (CEOI16_match) C++11
37 / 100
2000 ms 944 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN=2000;
int n;
string input;
bool coba(int idx,stack<char> characters){
    for(int i = idx; i < n ;  i++) {
        if(!characters.empty() && characters.top() == input[i]) {
            characters.pop();
        } else {
            characters.push(input[i]);
        }            
    }
    return characters.empty();
}

bool possible(){
    stack <char> temp;
    return coba(0,temp);
}

string makeAns(){
    string ret="";

    stack <char> characters;
    for(int i = 0; i < n; i++) {
        characters.push(input[i]);

        if(characters.empty()||characters.top() != input[i]) {
            ret += "(";
        } else if(coba(i+1,characters)) {
            ret += "(";
        } else {
            characters.pop();
            characters.pop();
            ret += ")";
        }
    }

    return ret;
}

int main()
{
    cin>>input;
    n = input.length();

    if (possible()) {
        cout<<makeAns()<<endl;
    } else {
        printf("-1\n");
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 516 KB Output is correct
4 Correct 4 ms 516 KB Output is correct
5 Correct 4 ms 516 KB Output is correct
6 Correct 6 ms 516 KB Output is correct
7 Correct 9 ms 532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 516 KB Output is correct
4 Correct 4 ms 516 KB Output is correct
5 Correct 4 ms 516 KB Output is correct
6 Correct 6 ms 516 KB Output is correct
7 Correct 9 ms 532 KB Output is correct
8 Correct 122 ms 592 KB Output is correct
9 Correct 147 ms 672 KB Output is correct
10 Correct 97 ms 684 KB Output is correct
11 Correct 88 ms 684 KB Output is correct
12 Execution timed out 2044 ms 944 KB Time limit exceeded
13 Halted 0 ms 0 KB -