Submission #258517

#TimeUsernameProblemLanguageResultExecution timeMemory
258517arnold518Toilets (JOI16_toilets)C++14
100 / 100
107 ms7416 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll MAXN = 1e18; const int MAXM = 2e5; ll N, M; string S[MAXM+10]; ll K[MAXM+10]; ll sum=0, ans=1; int main() { int i, j; cin>>N>>M; for(i=1; i<=M; i++) cin>>S[i]>>K[i]; for(i=M; i>=1; i--) { ll t=0, k=0; for(j=S[i].size()-1; j>=0; j--) { if(S[i][j]=='F') t--; else t++; k=max(k, t); } ans=max(ans, max(sum+k, sum+t*(K[i]-1)+k)); sum+=K[i]*t; } if(sum>0) return !printf("-1\n"); printf("%lld\n", ans-1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...