답안 #198213

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198213 2020-01-25T06:49:22 Z parsa_mobed 괄호 문자열 (CEOI16_match) C++14
37 / 100
2000 ms 664 KB
#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 10;
int a[N], n;
string s;

bool isval()
{
    vector <char> vec;
    for (int i = 0; i < n; i++) {
        if (a[i] == -1) {
            if (vec.empty() || vec.back() != s[i]) return 0;
            vec.pop_back();
        }
        if (a[i] == 1) vec.push_back(s[i]);
        if (a[i] == 0) {
            if (vec.size() && vec.back() == s[i]) vec.pop_back();
            else vec.push_back(s[i]);
        }
    }
    return vec.empty();
}
int main()
{
    cin >> s;
    n = s.size();
    if (!isval()) return cout << -1 << "\n", 0;
    for (int i = 0; i < n; i++) {
        a[i] = 1;
        if (!isval()) a[i] = -1;
    }
    for (int i = 0; i < n; i++) cout << (a[i] == 1 ? '(' : ')');
    cout << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 4 ms 380 KB Output is correct
6 Correct 10 ms 376 KB Output is correct
7 Correct 17 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 4 ms 380 KB Output is correct
6 Correct 10 ms 376 KB Output is correct
7 Correct 17 ms 376 KB Output is correct
8 Correct 282 ms 404 KB Output is correct
9 Correct 294 ms 504 KB Output is correct
10 Correct 202 ms 508 KB Output is correct
11 Correct 160 ms 532 KB Output is correct
12 Execution timed out 2100 ms 664 KB Time limit exceeded
13 Halted 0 ms 0 KB -