이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define f(i) for (int i=0; i<4; i++)
using namespace std;
int dp[100005][4][4][4][4];
int d(int x, int y, int z)
{
if (x)
{
if (x==y && y==z)
return 1;
else if ((x==y)^(y==z)^(z==x))
return 2;
else
return 3;
}
if (y)
{
if (y==z)
return 1;
else
return 2;
}
return 1;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, ans=0;
cin >> n;
for (int i=0; i<=n; i++)
f(j) f(k) f(l) f(m)
dp[i][j][k][l][m]=-1e9;
dp[0][0][0][0][0]=0;
for (int i=1; i<=n; i++)
{
char c;
cin >> c;
int x=(c=='M'?1:(c=='F'?2:3));
f(j) f(k) f(l) f(m)
{
dp[i][j][x][l][m]=max(dp[i][j][x][l][m], dp[i-1][k][j][l][m]+d(k, j, x));
dp[i][j][k][l][x]=max(dp[i][j][k][l][x], dp[i-1][j][k][m][l]+d(m, l, x));
}
}
f(i) f(j) f(k) f(l)
ans=max(ans, dp[n][i][j][k][l]);
cout << ans;
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... |