This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* Murad Eynizade */
#include <bits/stdc++.h>
#define intt long long
#define FAST_READ ios_base::sync_with_stdio(0);cin.tie(0);
#define F first
#define S second
using namespace std;
const int sz = 100005;
int n , ty[sz] , dp[2][4][4][4][4];
string s;
int val(int a,int b,int c) {
int ret = 0;
for (int i = 1;i<4;i++)
if (a == i || b == i || c == i)ret++;
return ret;
}
int main()
{
FAST_READ;
cin>>n>>s;
for (int i = 0;i<n;i++) {
if (s[i] == 'M')ty[i] = 1;
if (s[i] == 'B')ty[i] = 2;
if (s[i] == 'F')ty[i] = 3;
}
int nw = 0 , old = 1;
for (int w = n - 1;w>=0;w--) {
old = 1 - old;
nw = 1 - nw;
for (int i = 0;i<4;i++)
for (int j = 0;j<4;j++)
for (int k = 0;k<4;k++)
for (int c = 0;c < 4;c++)
dp[nw][i][j][k][c] = max(dp[old][j][ty[w]][k][c] + val(i , j , ty[w]) , dp[old][i][j][c][ty[w]] + val(k,c,ty[w]));
}
cout<<dp[nw][0][0][0][0]<<endl;
}
# | 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... |