Submission #1087263

#TimeUsernameProblemLanguageResultExecution timeMemory
1087263akim9905Toilets (JOI16_toilets)C++17
36 / 100
14 ms5896 KiB
#include <bits/stdc++.h> using namespace std; #define fileio() freopen("input.txt","r",stdin); freopen("output.txt","w",stdout) #define fio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define all(x) (x).begin(), (x).end() #define allr(x) x.rbegin(), x.rend() #define cmprs(x) sort(all(x)),x.erase(unique(all(x)),x.end()) #define endl "\n" #define sp " " #define pb push_back #define lb lower_bound #define ub upper_bound #define F first #define S second #define rz resize #define sz(a) (int)(a.size()) #define clr(a) a.clear() typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<int, ll> pil; typedef tuple<int, int, int> tpi; typedef tuple<ll, ll, ll> tpl; typedef pair<double, ll> pdl; typedef pair<double, int> pdi; const int dx[] = {1,-1,0,0,1,1,-1,-1}; const int dy[] = {0,0,1,-1,1,-1,1,-1}; const ll MOD = 1e9+7; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3f; const int MAX = 101010; // PLZ CHK! ll N,M,K[MAX]; string A[MAX]; vector<int> FI; int main() { fio(); cin>>N>>M; for (int i=0; i<M; i++) cin>>A[i]>>K[i]; ll am=0,af=0,ans=0; for (int i=M-1; i>=0; i--) { ll m=0,f=0,mx=0; string s=A[i]; for (int j=sz(s)-1; j>=0; j--) { if (s[j]=='M') m++; else f++; if (m>=f+2) { mx=max(mx, m-f-1); } } ans=max(ans, am-af+K[i]*mx); am+=K[i]*m; af+=K[i]*f; } if (am>af) { cout<<-1; } else cout<<ans; // int m=0,f=0; // int ans=0; // for (int i=2*N; i>=1; i--) { // if (S[i]=='M') m++; // else f++; // if (m>=f+2) { // ans=max(ans, m-f-1); // } // } // cout<<(m>f?-1:ans); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...