This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// ~~ icebear love atttttttttttt ~~
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define rep(i, n) for(int i=0; i<(n); ++i)
#define red(i, n) for(int i=(n)-1; i>=0; --i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "miners"
const int MOD = 1e9 + 7;
const int inf = 1e9 + 27092008;
const ll LLinf = 1e18 + 27092008;
const int N = 2e5 + 5;
int n, a[N];
int dp[N][4][4][4][4];
void maximize(int &x, int y) {x = max(x, y);}
void solve() {
cin >> n;
FOR(i, 1, n) {
char c;
cin >> c;
if (c == 'M') a[i] = 1;
if (c == 'F') a[i] = 2;
if (c == 'B') a[i] = 3;
}
memset(dp, -0x3f, sizeof dp);
int INF = -dp[0][0][0][0][0], res = 0;
dp[0][0][0][0][0] = 0;
FOR(i, 0, n + 1) FOR(a1, 0, 3) FOR(a2, 0, 3) FOR(b1, 0, 3) FOR(b2, 0, 3)
if (dp[i][a1][a2][b1][b2] != -INF) {
maximize(res, dp[i][a1][a2][b1][b2]);
int cnt = 1;
if (a[i] != a1 && a1 != 0) cnt++;
if (a[i] != a2 && a1 != a2 && a1 != 0 && a2 != 0) cnt++;
maximize(dp[i + 1][a[i]][a1][b1][b2], dp[i][a1][a2][b1][b2] + cnt);
cnt = 1;
if (a[i] != b1 && b1 != 0) cnt++;
if (a[i] != b2 && b1 != b2 && b2 != 0 && b1 != 0) cnt++;
maximize(dp[i + 1][a1][a2][a[i]][b1], dp[i][a1][a2][b1][b2] + cnt);
}
cout << res-1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int tc = 1;
// cin >> tc;
while(tc--) solve();
return 0;
}
Compilation message (stderr)
miners.cpp: In function 'int main()':
miners.cpp:63:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
miners.cpp:64:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
64 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |