답안 #566922

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
566922 2022-05-23T06:24:41 Z piOOE 괄호 문자열 (CEOI16_match) C++17
37 / 100
2000 ms 1060 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) begin(x), end(x)
#define sz(x) ((int)size(x))
#define trace(x) cout << #x << ": " << (x) << endl;

typedef long long ll;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());



int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    int n = sz(s);
    string ans;
    ans.resize(n, '?');
    auto check = [](string s, string ans) {
        int n = sz(s);
        vector<int> st;
        for (int i = 0; i < n; ++i) {
            if (ans[i] == '?') {
                if (st.empty()) {
                    st.push_back(i);
                } else {
                    if (s[st.back()] == s[i]) {
                        st.pop_back();
                    } else {
                        st.push_back(i);
                    }
                }
            } else if (ans[i] == '('){
                st.push_back(i);
            } else {
                if (st.empty() || s[st.back()] != s[i]) {
                    return false;
                }
                st.pop_back();
            }
        }
        return st.empty();
    };
    for (int i = 0; i < n; ++i) {
        ans[i] = '(';
        if (check(s, ans)) continue;
        ans[i] = ')';
        if (!check(s, ans)) {
            cout << -1;
            return 0;
        }
    }
    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 7 ms 328 KB Output is correct
5 Correct 8 ms 212 KB Output is correct
6 Correct 13 ms 212 KB Output is correct
7 Correct 27 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 7 ms 328 KB Output is correct
5 Correct 8 ms 212 KB Output is correct
6 Correct 13 ms 212 KB Output is correct
7 Correct 27 ms 324 KB Output is correct
8 Correct 283 ms 340 KB Output is correct
9 Correct 348 ms 364 KB Output is correct
10 Correct 307 ms 376 KB Output is correct
11 Correct 261 ms 396 KB Output is correct
12 Execution timed out 2074 ms 1060 KB Time limit exceeded
13 Halted 0 ms 0 KB -