답안 #1032640

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1032640 2024-07-24T04:59:20 Z 정민찬(#10967) 괄호 문자열 (CEOI16_match) C++17
37 / 100
2000 ms 668 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

string s;

bool Check(vector<char> st, int idx) {
    for (int i=idx; i<s.size(); i++) {
        if (!st.empty() && st.back() == s[i]) st.pop_back();
        else st.push_back(s[i]);
    }
    return st.empty();
}

int main() {
    ios_base :: sync_with_stdio(false); cin.tie(NULL);
    cin >> s;
    if (!Check({}, 0)) {
        cout << "-1\n";
        return 0;
    }
    vector<char> st;
    string ans;
    for (int i=0; i<s.size(); i++) {
        st.push_back(s[i]);
        if (!Check(st, i+1)) {
            st.pop_back();
            assert(st.back() == s[i]);
            st.pop_back();
            ans += ")";
        }
        else ans += "(";
    }
    cout << ans << '\n';
}

Compilation message

match.cpp: In function 'bool Check(std::vector<char>, int)':
match.cpp:11:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for (int i=idx; i<s.size(); i++) {
      |                     ~^~~~~~~~~
match.cpp: In function 'int main()':
match.cpp:27:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for (int i=0; i<s.size(); i++) {
      |                   ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
8 Correct 37 ms 480 KB Output is correct
9 Correct 45 ms 348 KB Output is correct
10 Correct 43 ms 344 KB Output is correct
11 Correct 40 ms 348 KB Output is correct
12 Execution timed out 2063 ms 668 KB Time limit exceeded
13 Halted 0 ms 0 KB -