이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
Editor: Abdelrahman Hossam
Nickname: Blobo2_Blobo2
I love my mama
*/
/*#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loop")*/
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define endl "\n"
#define all(v) v.begin(),v.end()
#define gen(arr,n,nxt) generate(arr,arr+n,nxt)
#define Blobo2 ios_base::sync_with_stdio(false);cin.tie(0);
const int mo=998244353;
inline int nxt(){int x;cin>>x;return x;}
int arr[100000],n;
int dp[100000][4][4][4][4];
bool freq[4];
int val(int x,int y,int z){
memset(freq,0,sizeof freq);
freq[x]=1;
freq[y]=1;
freq[z]=1;
int cnt = 3;
for(int i=0;i<3;i++)if(freq[i] == 0)cnt--;
return cnt;
}
int solve(int idx = 0,int x1 = 3,int y1 = 3,
int x2 = 3,int y2 = 3){
if(idx == n)return 0;
int &ret = dp[idx][x1][y1][x2][y2];
if(~ret)return ret;
return ret = max(val(arr[idx],x1,y1) + solve(idx+1, arr[idx], x1, x2, y2),
val(arr[idx],x2,y2) + solve(idx+1, x1, y1, arr[idx], x2));
}
void testCase(){
n=nxt();
string s;
cin>>s;
memset(dp,-1,sizeof dp);
for(int i=0;i<n;i++){
if(s[i] == 'M')arr[i] = 0;
if(s[i] == 'F')arr[i] = 1;
if(s[i] == 'B')arr[i] = 2;
}
cout<<solve()<<endl;
return;
}
signed main(){
Blobo2
int qu=1;
while(qu--){
testCase();
}
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... |