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 <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
#include <stack>
#define ff first
#define ss second
using namespace std;
string s;
int n, comma[7000005];
void pre() {
stack<int> st;
for(int i = 0; i < s.size(); i++) {
if(s[i] == ')') {
if(s[i + 1] == ',') {
comma[st.top()] = i + 1;
st.pop();
}
}
if(s[i] == '(') {
if(s[i + 2] == ',') comma[i] = i + 2;
else st.push(i);
}
}
}
pair<int, int> solve(int l, int r) {
if(l == r) return {0, 0};
int cnt = 0, x = comma[l + 3];
pair<int, int> a = solve(4 + l, x - 1), b = solve(x + 1, r - 1);
if(s[1 + l] == 'i') return {a.ff + b.ff + 1, min(a.ss, b.ss)};
else return {min(a.ff, b.ff), a.ss + b.ss + 1};
return {0, 0};
}
int main() {
memset(comma, -1, sizeof(comma));
ios::sync_with_stdio(0);cin.tie(0);
cin >> s;
pre();
n = (int)s.size() / 7 + 1;
pair<int, int> ans = solve(0, (int)s.size() - 1);
cout << n - ans.ff - ans.ss;
}
Compilation message (stderr)
Main.cpp: In function 'void pre()':
Main.cpp:29:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i = 0; i < s.size(); i++) {
| ~~^~~~~~~~~~
Main.cpp: In function 'std::pair<int, int> solve(int, int)':
Main.cpp:45:6: warning: unused variable 'cnt' [-Wunused-variable]
45 | int cnt = 0, x = comma[l + 3];
| ^~~
# | 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... |