# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
703081 | 2023-02-26T01:45:57 Z | nianny | Homework (CEOI22_homework) | C++17 | 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
# | 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 | - |