This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <fstream>
using namespace std;
vector<vector<vector<vector<vector <vector<int> > > > > >dp;
int maximo(int u1,int u2,int v1,int v2,int n,vector<int>a,int cu,int cv){
if(n==a.size()){
return cu+cv;
}
int x,x1;
if(u1!=-1 && u2!=-1){
if(u1!=u2 && u1!=a[n] && a[n]!=u2)x=3;
else if(u1!=u2 || u1!=a[n]||u2!=a[n])x=2;
else x=1;
}
else if(u2!=-1){
x1=0;
if(u2!=a[n])x=2;
else x=1;
}
else{
x=1;
x1=0;
}
int y,y1;
if(v1!=-1 && v2!=-1){
if(v1!=v2 && v1!=a[n] && a[n]!=v2)y=3;
else if(v1!=v2 || v1!=a[n]||v2!=a[n])y=2;
else y=1;
}
else if(v2!=-1){
y1=0;
if(v2!=a[n])y=2;
else y=1;
}
else{
y=1;
y1=0;
}
y1=0;
x1=0;
if(dp[cu+cv][u1+1][u2+1][v1+1][v2+1][n]!=-1)return dp[cu+cv][u1+1][u2+1][v1+1][v2+1][n];
return dp[cu+cv][u1+1][u2+1][v1+1][v2+1][n]=max(maximo(u2,a[n],v1,v2,n+1,a,cu+x,cv),maximo(u1,u2,v2,a[n],n+1,a,cu,cv+y));
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
string s;
cin>>s;
vector<int>a(n);
for(int i=0;i<n;i++){
if(s[i]=='M')a[i]=0;
else if(s[i]=='B')a[i]=1;
else a[i]=2;
}
dp.resize(3*(n-1)+1);
vector<int>j(n,-1);
vector<vector<int> >l(4);
for(int i=0;i<4;i++)l[i]=j;
vector<vector<vector<int> > >f(4);
for(int i=0;i<4;i++)f[i]=l;
vector<vector<vector<vector<int> > > >g(4);
for(int i=0;i<4;i++)g[i]=f;
vector<vector<vector<vector<vector<int> > > > >h(4);
for(int i=0;i<4;i++)h[i]=g;
for(int i=0;i<=3*(n-1);i++)dp[i]=h;
cout<<maximo(-1,-1,-1,-1,0,a,0,0);
return 0;
}
Compilation message (stderr)
miners.cpp: In function 'int maximo(int, int, int, int, int, std::vector<int>, int, int)':
miners.cpp:14:5: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | if(n==a.size()){
| ~^~~~~~~~~~
miners.cpp:17:7: warning: variable 'x1' set but not used [-Wunused-but-set-variable]
17 | int x,x1;
| ^~
miners.cpp:32:7: warning: variable 'y1' set but not used [-Wunused-but-set-variable]
32 | int y,y1;
| ^~
# | 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... |