이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define ld long double
#define st first
#define nd second
#define pb push_back
#define INF INT_MAX
using namespace std;
const int N = 1e5 + 10;
ll dp[N][4][4][4][4];
int f[N];
int g(vector<int> v) {
int ret = 0;
for (int i = 1; i <= 3; ++i) {
for (auto j : v) {
if (j == i) {
++ret;
break;
}
}
}
return ret;
}
void solve() {
int n; cin >> n;
string s; cin >> s;
for (int i = 1; i <= n; ++i) {
if (s[i-1] == 'M') f[i] = 1;
if (s[i-1] == 'F') f[i] = 2;
if (s[i-1] == 'B') f[i] = 3;
}
memset(dp, -1, sizeof(dp));
dp[0][0][0][0][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int s1 = 0; s1 < 4; ++s1) {
for (int s2 = 0; s2 < 4; ++s2) {
for (int s3 = 0; s3 < 4; ++s3) {
for (int s4 = 0; s4 < 4; ++s4) {
if (dp[i-1][s1][s2][s3][s4] == -1) continue;
int l = g({s1, s2, f[i]});
dp[i][s2][f[i]][s3][s4] = max(dp[i][s2][f[i]][s3][s4], dp[i-1][s1][s2][s3][s4] + l);
l = g({s3, s4, f[i]});
dp[i][s1][s2][s4][f[i]] = max(dp[i][s1][s2][s4][f[i]], dp[i-1][s1][s2][s3][s4] + l);
}
}
}
}
}
ll ans = 0;
for (int s1 = 0; s1 < 4; ++s1) {
for (int s2 = 0; s2 < 4; ++s2) {
for (int s3 = 0; s3 < 4; ++s3) {
for (int s4 = 0; s4 < 4; ++s4) {
ans = max(ans, dp[n][s1][s2][s3][s4]);
}
}
}
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
# | 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... |