# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
703072 | PenguinsAreCute | Homework (CEOI22_homework) | C++17 | 1075 ms | 33628 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] == 63) N++;
pair<pair<int,int>,bool> data[N - 1]; pair<int,int> value[N];
value[N - 1] = make_pair(1, N);
int cnt = 0;
for(int i = 0; i < S.size(); i++) {
if(S[i] == 109) {
data[cnt].s = (S[i + 1] == 97);
if(S[i + 4] == 63) data[cnt].f.f = N - 1;
else data[cnt].f.f = cnt + 1;
int j = i + 3, bC = 0, mC = 0;
while(S[j] != 44 || bC != 0) {
j++;
if(S[j] == 109) mC++;
if(S[j] == 40) bC++;
else if(S[j] == 41) bC--;
}
if(S[j + 1] == '?') data[cnt].f.s = N - 1;
else data[cnt].f.s = cnt + mC + 1;
cnt++;
}
}
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... |