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 <bits/stdc++.h>
using namespace std;
int c,d,x,y,z,n;
int i,j,k;
typedef pair<int,int>i2;
string s;
int a[200005],f[200005][4][4][4][4];
long long dp(int id,i2 x,i2 y)
{
if (id>n) return 0;
if (f[id][x.first+1][x.second+1][y.first+1][y.second+1]!=-1) return
f[id][x.first+1][x.second+1][y.first+1][y.second+1];
vector<int>b; int d=0;
b.push_back(x.first);
b.push_back(x.second);
b.push_back(a[id]);
sort(b.begin(),b.end());
d=1;
for (int i=1;i<b.size();i++)
if (b[i]!=b[i-1]) d++;
if (b[0]==-1) d--;
long long ans=dp(id+1,{x.second,a[id]},y)+d;
b.clear();
b.push_back(y.first);
b.push_back(y.second);
b.push_back(a[id]);
sort(b.begin(),b.end());
d=1;
for (int i=1;i<b.size();i++)
if (b[i]!=b[i-1]) d++;
if (b[0]==-1) d--;
ans=max(ans,dp(id+1,x,{y.second,a[id]})+d);
return f[id][x.first+1][x.second+1][y.first+1][y.second+1]=ans;
}
int main()
{
// freopen("MINERS.INP", "r" ,stdin);
// freopen("MINERS.OUT", "w" ,stdout);
// freopen("tongab.inp", "r" ,stdin);
// freopen("tongab.txt", "w" ,stdout);
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n;
for (int i=1;i<=n;i++)
for (int x1=0;x1<=3;x1++)
for (int x2=0;x2<=3;x2++)
for (int y1=0;y1<=3;y1++)
for (int y2=0;y2<=3;y2++)
f[i][x1][x2][y1][y2]=-1;
cin>>s; s='0'+s;
for (int i=1;i<=n;i++)
if (s[i]=='M') a[i]=0; else
if (s[i]=='B') a[i]=1; else a[i]=2;
c=dp(1,{-1,-1},{-1,-1});
cout<<c;
}
Compilation message (stderr)
miners.cpp: In function 'long long int dp(int, i2, i2)':
miners.cpp:19:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int i=1;i<b.size();i++)
| ~^~~~~~~~~
miners.cpp:29:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (int i=1;i<b.size();i++)
| ~^~~~~~~~~
# | 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... |