# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
239049 | T0p_ | Miners (IOI07_miners) | C++14 | 177 ms | 512 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;
long long dp[2][4][4][4][4];
map<char, int> mp;
int cost(int a, int b, int c)
{
int ret = 0;
if(a == 1 || b == 1 || c == 1) ret++;
if(a == 2 || b == 2 || c == 2) ret++;
if(a == 3 || b == 3 || c == 3) ret++;
return ret;
}
int main()
{
mp['M'] = 1;
mp['B'] = 2;
mp['F'] = 3;
for(int i=0 ; i<2 ; i++)
for(int j=0 ; j<4 ; j++)
for(int k=0 ; k<4 ; k++)
for(int l=0 ; l<4 ; l++)
for(int m=0 ; m<4 ; m++)
dp[i][j][k][l][m] = -1e18;
dp[0][0][0][0][0] = 0;
int n;
scanf(" %d",&n);
for(int i=1 ; i<=n ; i++)
{
char c;
scanf(" %c",&c);
int z = mp[c];
for(int j=0 ; j<4 ; j++)
for(int k=0 ; k<4 ; k++)
for(int l=0 ; l<4 ; l++)
for(int m=0 ; m<4 ; m++)
{
dp[i%2][k][z][l][m] = max(dp[i%2][k][z][l][m], dp[(i-1)%2][j][k][l][m] + cost(j, k, z));
dp[i%2][j][k][m][z] = max(dp[i%2][j][k][m][z], dp[(i-1)%2][j][k][l][m] + cost(l, m, z));
}
}
long long ans = -1e18;
for(int j=0 ; j<4 ; j++)
for(int k=0 ; k<4 ; k++)
for(int l=0 ; l<4 ; l++)
for(int m=0 ; m<4 ; m++)
ans = max(ans, dp[n%2][j][k][l][m]);
printf("%lld\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... |