# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
113418 | TadijaSebez | Miners (IOI07_miners) | C++11 | 67 ms | 768 KiB |
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;
const int N=100050;
const int inf=1e9+7;
int a[N];
char s[N];
int dp[2][4][4][4][4];
void ckmx(int &a, int b){ a=max(a,b);}
int pre[4][4][4];
int Get(int a, int b, int c)
{
return pre[a][b][c];
}
int Get1(int a, int b, int c)
{
set<int> st;
if(a) st.insert(a);
if(b) st.insert(b);
if(c) st.insert(c);
return st.size();
}
void Clear(int t)
{
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
for(int k=0;k<4;k++)
for(int l=0;l<4;l++)
dp[t][i][j][k][l]=-inf;
}
void Build()
{
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
for(int k=0;k<4;k++)
pre[i][j][k]=Get1(i,j,k);
}
int main()
{
Build();
int n,i;
scanf("%i",&n);
scanf("%s",s+1);
for(int i=1;i<=n;i++)
{
if(s[i]=='M') a[i]=1;
if(s[i]=='B') a[i]=2;
if(s[i]=='F') a[i]=3;
}
int c=0,p=1;
Clear(p);
dp[p][0][0][0][0]=0;
for(int t=1;t<=n;t++)
{
int tmp=a[t];
Clear(c);
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
for(int k=0;k<4;k++)
for(int l=0;l<4;l++)
{
ckmx(dp[c][i][j][l][tmp],dp[p][i][j][k][l]+Get(k,l,tmp));
ckmx(dp[c][j][tmp][k][l],dp[p][i][j][k][l]+Get(i,j,tmp));
}
swap(c,p);
}
int ans=-inf;
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
for(int k=0;k<4;k++)
for(int l=0;l<4;l++)
ans=max(ans,dp[p][i][j][k][l]);
printf("%i\n",ans);
return 0;
}
Compilation message (stderr)
# | 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... |