Submission #192210

#TimeUsernameProblemLanguageResultExecution timeMemory
192210dndhkToilets (JOI16_toilets)C++14
100 / 100
35 ms5948 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAX_N = 100000; ll N; int M; string str[MAX_N+1]; ll num[MAX_N+1]; ll ans = 0; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>N>>M; for(int i=1; i<=M; i++){ cin>>str[i]; cin>>num[i]; } ll sum = 0; for(int i=M; i>=1; i--){ ll S = 0; for(int j=0; j<str[i].size(); j++){ if(str[i][j]=='M') S++; else S--; } if(S>0){ sum+=(num[i]-1LL)*S; } for(int j=str[i].size()-1; j>=0; j--){ if(str[i][j]=='M') sum++; else{ sum--; ans = max(ans, sum); } } if(S<=0){ sum+=(num[i]-1LL)*S; } } if(sum>0) cout<<-1; else cout<<ans; return 0; }

Compilation message (stderr)

toilets.cpp: In function 'int main()':
toilets.cpp:30:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0; j<str[i].size(); j++){
                ~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...