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>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
#define en cin.close();return 0;
#define pb push_back
#define fi first//printf("%lli\n",cur);
#define se second//scanf("%lli",&n);
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e6+5;
vector<int> mid[N];
string str;
int go2(int l, int r, int op)
{
if(l==r)
return 0;
int pos = mid[op].back();
mid[op].pop_back();
int l1 = go2(l+4,pos-1,op+1), r1 = go2(pos+1,r-1,op+1);
if(str[l+1]=='i')
return min(l1,0)+min(r1,0)-1;
else
return max(l1,0)+max(r1,0)+1;
}
int main()
{
fio
// ifstream cin("in.in");
cin >> str;
int n = 0, op = 0;
for(int i = str.size()-1;i>=0;i--)
{
n+=(str[i]=='?');
op+=(str[i]==')')-(str[i]=='(');
if(str[i]==',')
mid[op].pb(i);
}
cout << n-abs(go2(0,str.size()-1,1));
// cin.close();
return 0;
}
# | 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... |