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;
#pragma optimize("O3")
typedef int ll;
#define x first
#define y second
#define pll pair<ll,ll>
string s;
ll n=0;
pll sol1(ll a, ll c)
{
if(s[a]=='?')return {a+1,c};
if(s[a+2]=='n'){
pll o1=sol1(a+4,c);
pll o2=sol1(o1.x+1,c);
return {o2.x+1,min(o1.y,o2.y)};
}
else{
pll o1=sol1(a+4,c);
pll o2=sol1(o1.x+1,o1.y+1);
return {o2.x+1,o2.y};
}
}
pll sol2(ll a, ll c)
{
if(s[a]=='?')return {a+1,c};
if(s[a+2]=='n'){
pll o1=sol2(a+4,c);
pll o2=sol2(o1.x+1,o1.y-1);
return {o2.x+1,o2.y};
}
else{
pll o1=sol2(a+4,c);
pll o2=sol2(o1.x+1,c);
return {o2.x+1,max(o1.y,o2.y)};
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>s;
for(auto i:s)n+=(i=='?');
cout<<sol2(0,n).y-sol1(0,1).y+1;
return 0;
}
Compilation message (stderr)
Main.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
3 | #pragma optimize("O3")
|
# | 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... |