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 int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int memo[100005][4][4][4][4], n;
int A[100005];
int dp(int x, int ls, int ls2, int pr, int pr2){
if(x == n + 1)return 0;
if(memo[x][ls][ls2][pr][pr2] != -1)return memo[x][ls][ls2][pr][pr2];
int tmp = 0;
if(ls == 1 || ls2 == 1 || A[x] == 1)tmp++;
if(ls == 2 || ls2 == 2 || A[x] == 2)tmp++;
if(ls == 3 || ls2 == 3 || A[x] == 3)tmp++;
tmp += dp(x + 1, A[x], ls, pr, pr2);
int tmp2 = 0;
if(pr == 1 || pr2 == 1 || A[x] == 1)tmp2++;
if(pr == 2 || pr2 == 2 || A[x] == 2)tmp2++;
if(pr == 3 || pr2 == 3 || A[x] == 3)tmp2++;
tmp2 += dp(x + 1, ls, ls2, A[x], pr);
return memo[x][ls][ls2][pr][pr2] = max(tmp, tmp2);
}
void solve(){
cin >> n;
for(int i = 1; i <= n; i++){
char x; cin >> x;
if(x == 'M')A[i] = 1;
if(x == 'B')A[i] = 2;
if(x == 'F')A[i] = 3;
}
memset(memo, -1, sizeof(memo));
cout << dp(1, 0, 0, 0, 0) << '\n';
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int tc = 1;
//cin >> tc;
for(int tc1=1;tc1<=tc;tc1++){
// cout << "Case #" << tc1 << ": ";
solve();
}
}
Compilation message (stderr)
miners.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
45 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |