Submission #1036784

#TimeUsernameProblemLanguageResultExecution timeMemory
1036784vjudge1Homework (CEOI22_homework)C++17
100 / 100
85 ms45568 KiB
#include<bits/stdc++.h>
#define F first
#define S second
#define MAX 500005
#define oo 1e18
#define mod 1000000007
#define fast_in ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.setf(ios::fixed);cout.precision(0);
using namespace std;
typedef long long ll;
#define pll pair<ll , ll>
#define vll vector<ll>
#define vvll vector<vll>
#define vpll vector<pll>
 
ll n,mx,mn;
string a;
pll exmx(ll x,ll y){ 
   //    cout<<x<<" "<<y<<"\n";
    if(a[x]=='?'){
        return {x+1,y};
    }
    if(a[x]=='m'){
        x+=1;
        if(a[x]=='a'){
            pll x1=exmx(x+3,y);
            pll x2=exmx(x1.F+1,y);
            return {x2.F+1,max(x1.S,x2.S)};
        }
        else{
            pll x1=exmx(x+3,y);
            pll x2=exmx(x1.F+1,x1.S-1);
            return {x2.F+1,x2.S};
        }
    }
}
pll exmn(ll x,ll y){ 
    if(a[x]=='?'){
        return {x+1,y};
    }
    if(a[x]=='m'){
        x+=1;
        if(a[x]=='i'){
            pll x1=exmn(x+3,y);
            pll x2=exmn(x1.F+1,y);
            return {x2.F+1,min(x1.S,x2.S)};
        }
        else{
            pll x1=exmn(x+3,y);
            pll x2=exmn(x1.F+1,x1.S+1);
            return {x2.F+1,x2.S};
        }
    }
}
int main(){
    fast_in
    cin>>a;
    for(int i=0;i<a.size();i++){
        if(a[i]=='?')n++;
    }
    pll a=exmx(0,n);
   // cout<<a.S<<" "<<a.F<<"\n";
    pll b=exmn(0,1);
  //  cout<<b.S<<" "<<b.F<<"\n";
    cout<<(a.S+1)-b.S;
return 0;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:57:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for(int i=0;i<a.size();i++){
      |                 ~^~~~~~~~~
Main.cpp: In function 'std::pair<long long int, long long int> exmx(ll, ll)':
Main.cpp:35:1: warning: control reaches end of non-void function [-Wreturn-type]
   35 | }
      | ^
Main.cpp: In function 'std::pair<long long int, long long int> exmn(ll, ll)':
Main.cpp:53:1: warning: control reaches end of non-void function [-Wreturn-type]
   53 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...