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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define sz(x) (int)(x.size())
using namespace std;
using namespace __gnu_pbds;
typedef
tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
int n, k, m;
string seq;
vector<vector<vector<vector<vector<int>>>>> memo;
int dp(int empl, pair<int, int> prec1, pair<int, int> prec2) {
if (empl>=n) return 0;
if (memo[empl][prec1.first][prec1.second][prec2.first][prec2.second]!=-1) {
return memo[empl][prec1.first][prec1.second][prec2.first][prec2.second];
}
int vaut=1;
if (seq[empl]=='F') vaut=2;
if (seq[empl]=='B') vaut=3;
int s1=dp(empl+1, {prec1.second, vaut}, prec2);
int s2=dp(empl+1, prec1, {prec2.second, vaut});
set<int> f1, f2;
f1.insert(vaut), f2.insert(vaut);
f1.insert(prec1.first), f1.insert(prec1.second);
f2.insert(prec2.first), f2.insert(prec2.second);
s1+=f1.size()-f1.count(0);
s2+=f2.size()-f2.count(0);
return memo[empl][prec1.first][prec1.second][prec2.first][prec2.second]=max(s1, s2);
}
void solve() {
cin >> n;
cin >> seq;
memo.clear();
memo.resize(n, vector<vector<vector<vector<int>>>>(4,
vector<vector<vector<int>>> (4, vector<vector<int>> (4, vector<int>(4, -1)))));
cout << dp(0, {0, 0}, {0, 0}) << endl;
return;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int tt=1;// cin >> tt;
while(tt--) solve();
return 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... |