이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5 + 5;
int dp[mx][4][4][4][4];
bool v[mx][4][4][4][4];
map<char, int> mp;
int cnt(int l1, int l2, char c){
set<int> st;
if (l1 != 0) st.insert(l1);
if (l2 != 0) st.insert(l2);
st.insert(mp[c]);
return st.size();
}
int main() {
int n; cin >> n;
string str; cin >> str;
mp['B'] = 1, mp['F'] = 2, mp['M'] = 3;
v[0][0][0][0][0] = true;
for (int i = 0; i < n; ++i){
for (int l11 = 0; l11 < 4; ++l11){
for (int l12 = 0; l12 < 4; ++l12){
for (int l21 = 0; l21 < 4; ++l21){
for (int l22 = 0; l22 < 4; ++l22){
if (!v[i][l11][l12][l21][l22]) continue;
dp[i+1][l12][mp[str[i]]][l21][l22] = max(dp[i+1][l12][mp[str[i]]][l21][l22], dp[i][l11][l12][l21][l22] + cnt(l11, l12, str[i]));
v[i+1][l12][mp[str[i]]][l21][l22] = true;
dp[i+1][l11][l12][l22][mp[str[i]]] = max(dp[i+1][l11][l12][l22][mp[str[i]]], dp[i][l11][l12][l21][l22] + cnt(l21, l22, str[i]));
v[i+1][l11][l12][l22][mp[str[i]]] = true;
}
}
}
}
}
int MX = 0;
for (int l11 = 0; l11 < 4; ++l11){
for (int l12 = 0; l12 < 4; ++l12){
for (int l21 = 0; l21 < 4; ++l21){
for (int l22 = 0; l22 < 4; ++l22){
if (!v[n][l11][l12][l21][l22]) continue;
MX = max(MX, dp[n][l11][l12][l21][l22]);
}
}
}
}
cout << MX << "\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... |