Submission #258511

#TimeUsernameProblemLanguageResultExecution timeMemory
258511arnold518Toilets (JOI16_toilets)C++14
36 / 100
20 ms7184 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; int M; string S[MAXM+10]; int K[MAXM+10]; int main() { int i, j; cin>>N>>M; for(i=1; i<=M; i++) cin>>S[i]>>K[i]; ll sum=0, ans=1; 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+(ll)t*(K[i]-1)+k)); sum+=(ll)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...