Submission #1011367

#TimeUsernameProblemLanguageResultExecution timeMemory
1011367pccToilets (JOI16_toilets)C++17
100 / 100
21 ms6860 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define fs first #define sc second ll N,M; vector<pair<string,ll>> v; int main(){ ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin>>N>>M; ll sum = 0,ans = 0; for(ll i = 0;i<M;i++){ string s; ll t; cin>>s>>t; reverse(s.begin(),s.end()); v.push_back(make_pair(s,t)); } reverse(v.begin(),v.end()); for(auto [s,t] : v){ ll ts = 0,tbig = -1e18; for(auto &i:s){ if(i == 'F'){ ts--; tbig = max(tbig,ts); } else ts++; } ans = max(ans,sum+tbig); sum += ts*(t-1); ans = max(ans,sum+tbig); sum += ts; } if(sum>0)cout<<"-1\n"; else cout<<ans<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...