Submission #1032666

# Submission time Handle Problem Language Result Execution time Memory
1032666 2024-07-24T05:57:19 Z 정민찬(#10967) Match (CEOI16_match) C++17
37 / 100
2000 ms 217720 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=l; i<=r; i++) {
        if (!st.empty() && st.back() == s[i]) st.pop_back();
        else st.push_back(s[i]);
        if (s[i] == s[l] && st.empty()) idx = i;
    }
    assert(st.empty());
    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:31:8: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |     Cal(idx+1, r);
      |     ~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Correct 32 ms 2024 KB Output is correct
10 Correct 18 ms 1884 KB Output is correct
11 Correct 32 ms 6100 KB Output is correct
12 Correct 1226 ms 159068 KB Output is correct
13 Correct 1423 ms 189264 KB Output is correct
14 Execution timed out 2072 ms 217720 KB Time limit exceeded
15 Halted 0 ms 0 KB -