이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/* 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... |