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 ll long long
string s;
vector<ll> pos[2];
ll N,M;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>N>>M;
if(N>1e6)return 0;
for(int i = 0;i<M;i++){
string t;
int c;
cin>>t>>c;
while(c--)s += t;
}
reverse(s.begin(),s.end());
ll sum = 0,ans = 0;
for(auto &i:s){
if(i == 'F'){
sum--;
ans = max(ans,sum);
}
else sum++;
}
if(sum>0)cout<<"-1\n";
else cout<<ans<<'\n';
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... |