# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
703081 | nianny | Homework (CEOI22_homework) | C++17 | 185 ms | 30808 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |