이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* 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];
int food [N];
int n, mask;
string w;
int calc (int a, int b, int c) {
mask = 0;
mask |= (1 << a);
mask |= (1 << b);
mask |= (1 << c);
mask &= ~1;
return __builtin_popcount(mask);
}
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 (int i = 0; i < n; i++) {
if (w[i] == 'M') food[i] = 1;
else if (w[i] == 'F') food[i] = 2;
else food[i] = 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... |