Submission #1032683

# Submission time Handle Problem Language Result Execution time Memory
1032683 2024-07-24T06:09:08 Z 정민찬(#10967) Match (CEOI16_match) C++17
100 / 100
1620 ms 86992 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();
}

void Cal(int l, int r) {
    if (l > r) return;
    vector<char> st;
    int idx;
    for (int i=r; i>=l; i--) {
        if (s[i] == s[l] && st.empty()) {
            idx = i;
            break;
        }
        if (!st.empty() && st.back() == s[i]) st.pop_back();
        else st.push_back(s[i]);
    }
    cout << "(";
    Cal(l+1, idx-1);
    cout << ")";
    Cal(idx+1, r);
}

int main() {
    ios_base :: sync_with_stdio(false); cin.tie(NULL);
    cin >> s;
    if (!Check({}, 0)) {
        cout << "-1\n";
        return 0;
    }
    Cal(0, s.size()-1);
}

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 'void Cal(int, int)':
match.cpp:33:8: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   33 |     Cal(idx+1, r);
      |     ~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 456 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 456 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 8 ms 860 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 2 ms 860 KB Output is correct
12 Correct 64 ms 9904 KB Output is correct
13 Correct 30 ms 6492 KB Output is correct
14 Correct 432 ms 50848 KB Output is correct
15 Correct 5 ms 4696 KB Output is correct
16 Correct 7 ms 4576 KB Output is correct
17 Correct 65 ms 6708 KB Output is correct
18 Correct 8 ms 2396 KB Output is correct
19 Correct 752 ms 48972 KB Output is correct
20 Correct 285 ms 38000 KB Output is correct
21 Correct 1620 ms 86992 KB Output is correct