답안 #341617

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
341617 2020-12-30T09:02:49 Z phathnv 괄호 문자열 (CEOI16_match) C++11
37 / 100
18 ms 508 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 2001;
const int AL = 26;

int n, answer[N];
string s;

void readInput(){
    cin >> s;
    n = s.size();
    s = '*' + s;
}

bool check(){
    stack <int> st;
    for(int i = 1; i <= n; i++)
        if (answer[i] != -1){
            if (answer[i] == 1)
                st.push(i);
            else if (!st.empty() && s[st.top()] == s[i])
                st.pop();
            else
                return 0;
        } else {
            if (!st.empty() && s[st.top()] == s[i])
                st.pop();
            else
                st.push(i);
        }
    return st.empty();
}

void solve(){
    for(int i = 1; i <= n; i++)
        answer[i] = -1;
    if (!check()){
        cout << -1;
        return;
    }
    for(int i = 1; i <= n; i++){
        answer[i] = 1;
        answer[i] = check();
    }
    for(int i = 1; i <= n; i++)
        cout << (answer[i] == 1? '(' : ')');
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    readInput();
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
5 Correct 4 ms 508 KB Output is correct
6 Correct 9 ms 364 KB Output is correct
7 Correct 18 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
5 Correct 4 ms 508 KB Output is correct
6 Correct 9 ms 364 KB Output is correct
7 Correct 18 ms 364 KB Output is correct
8 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Halted 0 ms 0 KB -