# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1011402 |
2024-06-30T13:11:00 Z |
kaopj |
Miners (IOI07_miners) |
C++17 |
|
77 ms |
101212 KB |
#pragma GCC optimize("O3","unroll-loops")
#include <iostream>
#include <string.h>
#define lgm cin.tie(0)->sync_with_stdio(0);
using namespace std;
signed main() {
lgm;
int n;
cin >> n;
char x[n+1];
int c[n];
cin >> x;
for (int i=0;i<n;i++) {
if (x[i] == 'M') {
c[i]=0;
} else if (x[i] == 'B') {
c[i]=1;
} else {
c[i]=2;
}
}
int dp[n+1][4][4][4][4];
memset(dp,0,sizeof dp);
int mx=0;
for (int i=1;i<=n;i++) {
for (int p1=0;p1<3;p1++) {
for (int p2=0;p2<3;p2++) {
for (int q1=0;q1<3;q1++) {
for (int q2=0;q2<3;q2++) {
int cnt1,cnt2;
if (p1 == p2 && c[i-1] == p1) {
cnt1=1;
} else if (p1 ^ p2 && c[i-1] ^ p1 && c[i-1] ^ p2) {
cnt1=3;
} else {
cnt1=2;
}
if (q1 == q2 && c[i-1] == q1) {
cnt2=1;
} else if (q1 ^ q2 && c[i-1] ^ q1 && c[i-1] ^ q2) {
cnt2=3;
} else {
cnt2=2;
}
dp[i][p2][c[i-1]][q1][q2]=max(dp[i][p2][c[i-1]][q1][q2],dp[i-1][p1][p2][q1][q2]+cnt1);
mx=max(mx,dp[i][p2][c[i-1]][q1][q2]);
dp[i][p1][p2][q2][c[i-1]]=max(dp[i][p1][p2][q2][c[i-1]],dp[i-1][p1][p2][q1][q2]+cnt2);
mx=max(mx,dp[i][p1][p2][q2][c[i-1]]);
}
}
}
}
}
cout << mx-6;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
10332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
25656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
76016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
101212 KB |
Output is correct |