이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n,a[100001],dp[100001][4][4][4][4];
string s;
set <int> sl,sr;
int f(int i, int j, int k, int l, int m){
if (i>n)
return 0;
if (dp[i][j][k][l][m]!=-1)
return dp[i][j][k][l][m];
sl.clear();
sr.clear();
if (j)
sl.insert(j);
if (k)
sl.insert(k);
if (l)
sr.insert(l);
if (m)
sr.insert(m);
sl.insert(a[i]);
sr.insert(a[i]);
int x=sl.size(),y=sr.size();
return dp[i][j][k][l][m]=max(f(i+1,k,a[i],l,m)+x,f(i+1,j,k,m,a[i])+y);
}
int main(){
ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
cin >> n >> s;
for (int i=1;i<=n;i++)
a[i]=(s[i-1]=='M'?1:s[i-1]=='F'?2:3);
memset(dp,-1,sizeof(dp));
cout << f(1,0,0,0,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... |