# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
192210 | dndhk | Toilets (JOI16_toilets) | C++14 | 35 ms | 5948 KiB |
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>
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |