Submission #703081

# Submission time Handle Problem Language Result Execution time Memory
703081 2023-02-26T01:45:57 Z nianny Homework (CEOI22_homework) C++17
0 / 100
185 ms 30808 KB
    #include <bits/stdc++.h>
    using namespace std;
    #define f first
    #define s second
    #define MP make_pair
    int main() {
        int N = 0; string S; cin >> S;
        for(int i = 0; i < S.size(); i++) if(S[i] == '?') N++;
        pair<pair<int,int>,bool> data[N - 1]; pair<int,int> value[N];
        for(int i = 0; i < N - 1; i++) {
            data[i].f.f = -1;
            data[i].f.s = -1;
        }
        value[N - 1] = make_pair(1, N);
        int cnt = 0; stack<int> st;
        for(int i = 0; i < S.size(); i++) {
            if(S[i] == '(') {
                data[cnt].s = (S[i - 2] == 'a');
                if(cnt != 0) {
                    if(data[st.top()].f.f == -1) data[st.top()].f.f = cnt;
                    else data[st.top()].f.s = cnt;
                }
                st.push(cnt);
                cnt++;
            } else if(S[i] == ')') {
                if(data[st.top()].f.f == -1) data[st.top()].f.f = N - 1;
                else data[st.top()].f.s = N - 1;
            } else if(S[i] == 41) st.pop();
        }
        for(int i = N - 2; i >= 0; i--) {
            if(data[i].s == false) {
                value[i].f = min(value[data[i].f.f].f, value[data[i].f.s].f);
                value[i].s = value[data[i].f.f].s + value[data[i].f.s].s - (N + 1);
            } else {
                value[i].f = value[data[i].f.f].f + value[data[i].f.s].f;
                value[i].s = max(value[data[i].f.f].s, value[data[i].f.s].s);
            }
        }
        cout << value[0].second - value[0].first + 1;
    }

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:9:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |         for(int i = 0; i < S.size(); i++) if(S[i] == '?') N++;
      |                        ~~^~~~~~~~~~
Main.cpp:17:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |         for(int i = 0; i < S.size(); i++) {
      |                        ~~^~~~~~~~~~
Main.cpp:10:34: warning: argument to variable-length array is too large [-Wvla-larger-than=]
   10 |         pair<pair<int,int>,bool> data[N - 1]; pair<int,int> value[N];
      |                                  ^~~~
Main.cpp:10:34: note: limit is 9223372036854775807 bytes, but argument is 18446744073709551604
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 185 ms 30808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -