# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
64676 | nvmdava | Miners (IOI07_miners) | C++17 | 328 ms | 101384 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 dp[100002][4][4][4][4];
int f(char c){
if(c == 'M'){
return 1;
} else if(c == 'B'){
return 2;
} else {
return 3;
}
}
int mine(int a, int b, int c){
int s = 0;
if (a == 1 || b == 1 || c == 1) s++;
if (a == 2 || b == 2 || c == 2) s++;
if (a == 3 || b == 3 || c == 3) s++;
return s;
}
int main(){
int len, i, w, j, l, m, n, k, t;
cin>>len;
string s;
cin>>s;
for(w = 0; w < len; w++){
t = f(s[w]);
for(j = 0; j <= 3; j++){
for(l = 0; l <= 3; l++){
for(m = 0; m <= 3; m++){
for(n = 0; n <= 3; n++){
dp[w + 1][l][t][m][n] = max(dp[w + 1][l][t][m][n], dp[w][j][l][m][n] + mine(j, l, t));
dp[w + 1][j][l][n][t] = max(dp[w + 1][j][l][n][t], dp[w][j][l][m][n] + mine(m, n, t));
}
}
}
}
}
int mx = -1;
w = len;
for(j = 0; j <= 3; j++){
for(l = 0; l <= 3; l++){
for(m = 0; m <= 3; m++){
for(n = 0; n <= 3; n++){
mx = max(mx, dp[w][j][l][m][n]);
}
}
}
}
cout<<mx - 6;
}
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... |