This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,O2,O3,unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << "[" << H << "]";
debug_out(T...);
}
#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define SZ(s) ((int)s.size())
#define all(x) (x).begin(), (x).end()
#define lla(x) (x).rbegin(), (x).rend()
clock_t startTime;
double getCurrentTime() {
return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}
#define MP make_pair
typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.00001;
const int MOD = 1e9 + 7;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 2e5 + 3e2;
const int M = 522;
int f(char c){
return (c == 'M' ? 0 : c == 'F' ? 1 : 2);
}
void chmax(int &a, int b){
a = max(a, b);
}
int code(vector<int> &v){
if (v.empty()) return 0;
if (v.size() == 1) return 1 + v[0];
return 4 + v[0] * 3 + v[1];
}
vector<int> decode(int x){
if (x == 0) return {};
x--;
if (x < 3) return {x};
x -= 3;
return {x / 3, x % 3};
}
int last, diff = 0;
void add(vector<int> &v, int x){
v.push_back(x);
diff = (count(all(v), 0) > 0) + (count(all(v), 1) > 0) + (count(all(v), 2) > 0);
if (v.size() > 2) v.erase(v.begin());
last = code(v);
}
int dp[2][13][13];
void solve(int TC) {
int n; string s;
cin >> n >> s;
for (int i = 0; i < 2; i++){
for (int j = 0; j < 13; j++){
for (int k = 0; k < 13; k++){
dp[i][j][k] = -INF;
}
}
}
int f0 = f(s[0]);
dp[0][f0 + 1][0] = dp[0][0][f0 + 1] = 1;
for (int i = 0; i < n - 1; i++){
int c = f(s[i + 1]);
int cur = 0;
for (int x = 0; x < 13; x++){
for (int y = 0; y < 13; y++){
cur = max(cur, dp[i % 2][x][y]);
vector<int> a = decode(x), b = decode(y);
add(a, c);
chmax(dp[1 - i % 2][last][y], dp[i % 2][x][y] + diff);
add(b, c);
chmax(dp[1 - i % 2][x][last], dp[i % 2][x][y] + diff);
}
}
debug(i, cur);
}
int ans = 0;
for (int i = 0; i < 13; i++){
for (int j = 0; j < 13; j++){
ans = max(ans, dp[(n - 1) % 2][i][j]);
}
}
cout << ans;
}
int main() {
startTime = clock();
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#ifdef dddxxz
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int TC = 1;
// cin >> TC;
for (int test = 1; test <= TC; test++) {
debug(test);
//cout << "Case #" << test << ": ";
solve(test);
}
//cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl;
return 0;
}
Compilation message (stderr)
miners.cpp: In function 'void solve(int)':
miners.cpp:19:20: warning: statement has no effect [-Wunused-value]
19 | #define debug(...) 42
| ^~
miners.cpp:107:9: note: in expansion of macro 'debug'
107 | debug(i, cur);
| ^~~~~
miners.cpp: In function 'int main()':
miners.cpp:19:20: warning: statement has no effect [-Wunused-value]
19 | #define debug(...) 42
| ^~
miners.cpp:136:9: note: in expansion of macro 'debug'
136 | debug(test);
| ^~~~~
# | 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... |