이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = 1e5+5;
int dp[2][4][4][4][4];
const int INF = 1e9+7;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
string s; cin >> s;
map<char,int> mp;
mp['M']=1;
mp['F']=2;
mp['B']=3;
memset(dp, -INF, sizeof(dp));
dp[1][0][0][0][0] = 0;
int ans = 0;
for (int i = 0; i <n; ++i) {
int ic = i%2;
int p = mp[s[i]];
//cerr << p << " ";
for (int j = 0; j <= 3; ++j) {for (int k = 0; k <= 3; ++k) {
for (int l = 0; l <= 3; ++l) {for (int m = 0; m <= 3; ++m) {
set<int> st;
st.insert(p);
st.insert(j);
st.insert(k);
st.erase(0);
int inc = st.size();
//if (p == 0 || j == 0 || k == 0) inc--;
dp[ic][p][j][l][m] = max(dp[ic][p][j][l][m],
inc+dp[ic^1][j][k][l][m]);
dp[ic][l][m][p][j] = max(dp[ic][l][m][p][j],
inc+dp[ic^1][l][m][j][k]);
}
}
}
}
}
for (int j = 0; j <= 3; ++j) {for (int k = 0; k <= 3; ++k) {
for (int l = 0; l <= 3; ++l) {for (int m = 0; m <= 3; ++m) {
ans = max(ans, dp[0][j][k][l][m]);
ans = max(ans, dp[1][j][k][l][m]);
}}}}
cout << ans << "\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... |