이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int dp[100005][4][4][4][4];
int main(){
int n; cin >> n;
memset(dp,0,sizeof dp);
dp[0][0][0][0][0] = 1;
for(int x = 0; x < n; ++x){
char c; cin >> c;
int val = 0;
if(c == 'M')val = 1;
if(c == 'B')val = 2;
if(c == 'F')val = 3;
for(int i = 0; i < 4; ++i){
for(int j = 0; j < 4; ++j){
for(int k = 0; k < 4; ++k){
for(int l = 0; l < 4; ++l){
if(!dp[x][i][j][k][l])continue;
set<int> ans1, ans2;
ans1.insert(i);
ans1.insert(j);
ans1.insert(val);
ans2.insert(k);
ans2.insert(l);
ans2.insert(val);
ans1.erase(0);
ans2.erase(0);
dp[x+1][j][val][k][l] = max(dp[x+1][j][val][k][l], dp[x][i][j][k][l]+(int)ans1.size());
dp[x+1][i][j][l][val] = max(dp[x+1][i][j][l][val], dp[x][i][j][k][l]+(int)ans2.size());
}
}
}
}
}
int ans = 0;
for(int i = 0; i < 4; ++i){
for(int j = 0; j < 4; ++j){
for(int k = 0; k < 4; ++k){
for(int l = 0; l < 4; ++l){
ans = max(ans, dp[n][i][j][k][l]);
}
}
}
}
cout << ans-1 << "\n";
}
# | 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... |