답안 #222989

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
222989 2020-04-14T12:49:39 Z Minnakhmetov 괄호 문자열 (CEOI16_match) C++14
37 / 100
2000 ms 608 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    cin >> s;

    int n = s.size();

    vector<char> stk;

    string ans;

    for (int i = 0; i < n; i++) {
        if (stk.empty() || stk.back() != s[i]) {
            stk.push_back(s[i]);
            ans.push_back('(');
        }
        else {
            vector<char> stk_cp = stk;
            stk_cp.push_back(s[i]);

            for (int j = i + 1; j < n; j++) {
                if (stk_cp.empty() || stk_cp.back() != s[j]) {
                    stk_cp.push_back(s[j]);
                }
                else {
                    stk_cp.pop_back();
                }
            }
            if (stk_cp.empty()) {
                stk.push_back(s[i]);
                ans.push_back('(');
            }
            else {
                stk.pop_back();
                ans.push_back(')');
            }
        }
    }

    if (stk.empty()) {
        cout << ans << "\n";
    }
    else {
        cout << "-1\n";
    }
 
    return 0;
}
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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 6 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 7 ms 384 KB Output is correct
7 Correct 8 ms 384 KB Output is correct
# 결과 실행 시간 메모리 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 6 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 7 ms 384 KB Output is correct
7 Correct 8 ms 384 KB Output is correct
8 Correct 51 ms 384 KB Output is correct
9 Correct 49 ms 384 KB Output is correct
10 Correct 42 ms 420 KB Output is correct
11 Correct 41 ms 512 KB Output is correct
12 Execution timed out 2097 ms 608 KB Time limit exceeded
13 Halted 0 ms 0 KB -