이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, ll> pdl;
typedef pair<ll, double> pld;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
// #define int long long
#define lowbit(x) x&-x
const int maxn = 1e3 + 5;
const int INF = 1e9;
map<char, int> mp = {{'M', 1}, {'F', 2}, {'B', 3}};
int dp[4][4][4][4], ndp[4][4][4][4];
int sol(int a, int b, int c){
if(a == 0){
if(b == 0) return 1;
return 2 - (b == c);
}
return 3 - (a == c) - (b == c) - (b == c) + (a == c && b == c);
}
signed main(void){
fastio;
int n;
cin>>n;
string s;
cin>>s;
for(int i = 0; i <= 3; i++){
for(int j = 0; j <= 3; j++){
for(int k = 0; k <= 3; k++){
for(int l = 0; l <= 3; l++){
dp[i][j][k][l] = -INF;
}
}
}
}
dp[0][0][0][0] = 0;
for(auto x : s){
for(int i = 0; i <= 3; i++){
for(int j = 0; j <= 3; j++){
for(int k = 0; k <= 3; k++){
for(int l = 0; l <= 3; l++){
ndp[i][j][k][l] = -INF;
}
}
}
}
int c = mp[x];
for(int i = 0; i <= 3; i++){
for(int j = 0; j <= 3; j++){
for(int k = 0; k <= 3; k++){
for(int l = 0; l <= 3; l++){
ndp[i][j][l][c] = max(ndp[i][j][l][c], dp[i][j][k][l] + sol(k, l, c));
}
}
}
}
for(int j = 0; j <= 3; j++){
for(int k = 0; k <= 3; k++){
for(int l = 0; l <= 3; l++){
for(int i = 0; i <= 3; i++){
ndp[j][c][k][l] = max(ndp[j][c][k][l], dp[i][j][k][l] + sol(i, j, c));
}
}
}
}
swap(dp, ndp);
}
int ans = 0;
for(int i = 0; i <= 3; i++){
for(int j = 0; j <= 3; j++){
for(int k = 0; k <= 3; k++){
for(int l = 0; l <= 3; l++){
ans = max(ans, dp[i][j][k][l]);
}
}
}
}
cout<<ans<<"\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... |