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>
#define INF 1e+18
#define int long long
using namespace std;
int knd(int a,int b,int c){
int cnt[4] = {};
if(!cnt[a]) cnt[a]++;
if(!cnt[b]) cnt[b]++;
if(!cnt[c]) cnt[c]++;
return cnt[1] + cnt[2] + cnt[3];
}
signed main(){
int n,dp[2][4][4][4][4],now = 0,nxt = 1,ma = 0;
string s;
cin >> n >> s;
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[0][i][j][k][l] = -INF;
dp[1][i][j][k][l] = -INF;
}
}
}
}
dp[0][0][0][0][0] = 0;
for(int i = 0;i < 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 m = 0;m < 4;m++){
int num,add = 0;
if(s[i] == 'M') num = 1;
else if(s[i] == 'B') num = 2;
else num = 3;
dp[nxt][k][num][l][m] = max(dp[nxt][k][num][l][m],dp[now][j][k][l][m] + knd(j,k,num));
dp[nxt][j][k][m][num] = max(dp[nxt][j][k][m][num],dp[now][j][k][l][m] + knd(l,m,num));
}
}
}
}
swap(now,nxt);
}
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++) ma = max(ma,dp[now][i][j][k][l]);
}
}
}
cout << ma << endl;
return 0;
}
Compilation message (stderr)
miners.cpp: In function 'int main()':
miners.cpp:34:15: warning: unused variable 'add' [-Wunused-variable]
int num,add = 0;
^~~
# | 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... |