답안 #940259

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940259 2024-03-07T07:12:58 Z thinknoexit 괄호 문자열 (CEOI16_match) C++17
10 / 100
10 ms 456 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
string s;
int ans[22], a[22];
bool ch = 0;
void solve(int bit) {
    stack<char> st;
    for (int i = 0;i < n;i++) {
        a[i] = (bit >> i) & 1;
        if (a[i]) {
            if (st.empty()) return;
            if (st.top() != s[i]) return;
            st.pop();
        }
        else {
            st.push(s[i]);
        }
    }
    if (!st.empty()) return;
    for (int i = 0;i < n;i++) {
        if (ans[i] != a[i]) {
            if (ans[i] > a[i]) {
                for (int i = 0;i < n;i++) ans[i] = a[i];
            }
            break;
        }
    }
    ch = 1;
}
int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    memset(ans, 0x3f, sizeof ans);
    cin >> s;
    n = s.size();
    for (int v = 0;v < (1 << n);v++) {
        solve(v);
    }
    if (!ch) cout << -1;
    else {
        for (int i = 0;i < n;i++) {
            cout << "()"[ans[i]];
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 10 ms 456 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 10 ms 456 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Runtime error 1 ms 348 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 10 ms 456 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Runtime error 1 ms 348 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -