# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1011301 | pcc | Toilets (JOI16_toilets) | C++17 | 6 ms | 3608 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>
using namespace std;
#define ll long long
string s;
vector<ll> pos[2];
ll N,M;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>N>>M;
if(N>1e6)return 0;
for(int i = 0;i<M;i++){
string t;
int c;
cin>>t>>c;
while(c--)s += t;
}
reverse(s.begin(),s.end());
pos[0].push_back(-1);
for(int i = 0;i<s.size();i++){
pos[s[i] == 'M'].push_back(i);
}
while(pos[0].size()>pos[1].size())pos[0].pop_back();
if(pos[0].size()<pos[1].size()){
cout<<"-1\n";
return 0;
}
ll ans = 0;
for(int i = 0;i<pos[0].size();i++){
auto it = upper_bound(pos[1].begin(),pos[1].end(),pos[0][i])-pos[1].begin();
ans = max(ans,1ll*it-i);
}
cout<<ans<<'\n';
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... |