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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define endl '\n'
#define fi first
#define se second
#define For(i, l, r) for (auto i = (l); i < (r); i++)
#define ForE(i, l, r) for (auto i = (l); i <= (r); i++)
#define FordE(i, l, r) for (auto i = (l); i >= (r); i--)
#define Fora(v, a) for (auto v: (a))
#define bend(a) (a).begin(), (a).end()
#define isz(a) ((signed)(a).size())
using ll = long long;
using ld = long double;
using pii = pair <int, int>;
using vi = vector <int>;
using vpii = vector <pii>;
using vvi = vector <vi>;
const int N = 1e5 + 5, inf = 1e9 + 7;
int n;
string s;
int dp[N][4][4][4][4];
int f(char c){
if (c == 'M'){
return 1;
}
if (c == 'F'){
return 2;
}
if (c == 'B'){
return 3;
}
return 0;
}
int g(int i, int j, int k){
int cnt[4] = {0, 0, 0, 0};
cnt[i]++; cnt[j]++; cnt[k]++;
return (cnt[1] ? 1 : 0) + (cnt[2] ? 1 : 0) + (cnt[3] ? 1 : 0);
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("KEK.inp", "r", stdin);
// freopen("KEK.out", "w", stdout);
cin >> n;
cin >> s;
memset(dp, 0xc0, sizeof(dp));
dp[0][0][0][0][0] = 0;
For(i, 0, n){
int ii = i & 1;
ForE(m12, 0, 3){
ForE(m11, 0, 3){
ForE(m22, 0, 3){
ForE(m21, 0, 3){
dp[i + 1][m11][f(s[i])][m22][m21] = max(dp[i + 1][m11][f(s[i])][m22][m21], dp[i][m12][m11][m22][m21] + g(m12, m11, f(s[i])));
dp[i + 1][m12][m11][m21][f(s[i])] = max(dp[i + 1][m12][m11][m21][f(s[i])], dp[i][m12][m11][m22][m21] + g(m22, m21, f(s[i])));
}
}
}
}
}
int ans = 0;
ForE(m12, 0, 3){
ForE(m11, 0, 3){
ForE(m22, 0, 3){
ForE(m21, 0, 3){
ans = max(ans, dp[n][m12][m11][m22][m21]);
}
}
}
}
cout << ans << endl;
}
/*
==================================================+
INPUT: |
--------------------------------------------------|
--------------------------------------------------|
==================================================+
OUTPUT: |
--------------------------------------------------|
--------------------------------------------------|
==================================================+
*/
Compilation message (stderr)
miners.cpp: In function 'int main()':
miners.cpp:61:13: warning: unused variable 'ii' [-Wunused-variable]
61 | int ii = i & 1;
| ^~
# | 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... |