이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
int n, arr[2*100005]; string s; map<char, int> m;
ll dp[2][4][4][4][4];
int solve(int i, int j, int k) {
int res = 0;
for(int l = 1; l <= 3; l++)
if(l == i || l == j || l == k) res++;
return res;
}
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> s; m['M'] = 1, m['B'] = 2, m['F'] = 3;
for(int l = 0; l < n; l++) arr[l + 1] = m[s[l]];
int a = 0, b = 1;
for(int l = n; l > 0; l--) {
swap(a, b);
for(int u0 = 0; u0 < 4; u0++)
for(int u = 0; u < 4; u++)
for(int v0 = 0; v0 < 4; v0++)
for(int v = 0; v < 4; v++)
dp[a][u0][u][v0][v] = max(dp[b][u][arr[l]][v0][v] + solve(u0, u, arr[l]),
dp[b][u0][u][v][arr[l]] + solve(v0, v, arr[l]));
}
cout << dp[a][0][0][0][0] << "\n";
return 0;
}
# | 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... |