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 = 100005, inf = 1e9;
int n, dt[2][4][4][4][4];
char a[N];
int val (int A, int B, int C) {
return ((A == 1) | (B == 1) | (C == 1)) +
((A == 2) | (B == 2) | (C == 2)) +
((A == 3) | (B == 3) | (C == 3));
}
int main()
{
scanf("%d%s",&n,a+1);
for(int j=0;j<256;j++) {
int A = j/64, B = j/16%4, C = j/4%4, D = j%4;
dt[0][A][B][C][D] = -inf;
}
dt[0][0][0][0][0] = 0;
for(int i=1;i<=n;i++) {
int E = (a[i] == 'M')*1 + (a[i] == 'B')*2 + (a[i] == 'F')*3;
for(int j=0;j<256;j++) {
int A = j/64, B = j/16%4, C = j/4%4, D = j%4;
dt[i%2][A][B][C][D] = -inf;
}
for(int j=0;j<256;j++) {
int A = j/64, B = j/16%4, C = j/4%4, D = j%4, P = dt[1-i%2][A][B][C][D];
dt[i%2][B][E][C][D] = max(dt[i%2][B][E][C][D], P + val(A, B, E));
dt[i%2][A][B][D][E] = max(dt[i%2][A][B][D][E], P + val(C, D, E));
}
}
int ans = 0;
for(int j=0;j<256;j++) {
int A = j/64, B = j/16%4, C = j/4%4, D = j%4;
ans = max(ans, dt[n%2][A][B][C][D]);
}
printf("%d\n",ans);
}
Compilation message (stderr)
miners.cpp: In function 'int main()':
miners.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%s",&n,a+1);
~~~~~^~~~~~~~~~~~~~~
# | 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... |