This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author: Duarte Nobrega
* created: 28.05.2020
**/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
const int N = 1e5 + 5;
int dp [N][4][4][4][4];
vector<int> food;
int n;
string w;
set<int> cnt;
int calc (int a, int b, int c) {
cnt.clear();
cnt.insert(a);
cnt.insert(b);
cnt.insert(c);
cnt.erase(0);
return (int) cnt.size();
}
int solve (int p = 0, int l1 = 0, int l2 = 0, int r1 = 0, int r2 = 0) {
if (p >= n) return 0;
int &res = dp[p][l1][l2][r1][r2];
if (~res) return res;
res = 0;
// Place left
res = max (res, solve (p + 1, food[p], l1, r1, r2) + calc (l1, l2, food[p]));
// Place right
res = max (res, solve (p + 1, l1, l2, food[p], r1) + calc (r1, r2, food[p]));
return res;
}
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
memset (dp, -1, sizeof(dp));
cin >> n >> w;
for (auto to : w) {
if (to == 'M') food.emplace_back(1);
else if (to == 'F') food.emplace_back(2);
else food.emplace_back(3);
}
cout << solve () << '\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... |