# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
428387 | ponkung | Miners (IOI07_miners) | C++14 | 1578 ms | 460 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;
int n,dp[2][4][4][4][4],val,mx=0;
char str[100005];
set<int> s;
int main()
{
for(int j=0;j<4;j++)
{
for(int k=0;k<4;k++)
{
for(int l=0;l<4;l++)
{
for(int c=0;c<4;c++)
{
dp[0][j][k][l][c]=-1e9;
}
}
}
}
dp[0][0][0][0][0]=0;
scanf("%d%s",&n,str+1);
for(int i=1;i<=n;i++)
{
//printf("%d\n",i);
for(int j=0;j<4;j++)
{
for(int k=0;k<4;k++)
{
for(int l=0;l<4;l++)
{
for(int c=0;c<4;c++)
{
dp[i%2][j][k][l][c]=-1e9;
}
}
}
}
if(str[i]=='M')
{
val=1;
}else if(str[i]=='F')
{
val=2;
}else
{
val=3;
}
for(int j=0;j<4;j++)
{
for(int k=0;k<4;k++)
{
for(int l=0;l<4;l++)
{
for(int c=0;c<4;c++)
{
if(j!=0)
{
s.insert(j);
}
if(k!=0)
{
s.insert(k);
}
s.insert(val);
dp[i%2][k][val][l][c]=max(dp[i%2][k][val][l][c],dp[1-(i%2)][j][k][l][c]+(int)s.size());
s.clear();
if(l!=0)
{
s.insert(l);
}
if(c!=0)
{
s.insert(c);
}
s.insert(val);
dp[i%2][j][k][c][val]=max(dp[i%2][j][k][c][val],dp[1-(i%2)][j][k][l][c]+(int)s.size());
s.clear();
}
}
}
}
/*for(int j=0;j<4;j++)
{
for(int k=0;k<4;k++)
{
for(int l=0;l<4;l++)
{
for(int c=0;c<4;c++)
{
printf("%d %d %d %d %d\n",j,k,l,c,dp[i%2][j][k][c][l]);
}
}
}
}*/
}
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++)
{
mx=max(mx,dp[n%2][i][j][k][l]);
}
}
}
}
printf("%d\n",mx);
}
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... |