Submission #899506

#TimeUsernameProblemLanguageResultExecution timeMemory
899506NonozeMiners (IOI07_miners)C++17
92 / 100
1529 ms238472 KiB
#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; map<char, int> vaut; map<pair<int, pair<pair<int, int>, pair<int, int>>>, int> memo; int dp(int empl, pair<int, int> prec1, pair<int, int> prec2) { if (empl>=n) return 0; if (memo.count({empl, {prec1, prec2}})) return memo[{empl, {prec1, prec2}}]; int s1=dp(empl+1, {prec1.second, vaut[seq[empl]]}, prec2); int s2=dp(empl+1, prec1, {prec2.second, vaut[seq[empl]]}); map<int, int> mp1; mp1[vaut[seq[empl]]]++; if (prec1.first!=-1) mp1[prec1.first]++; if (prec1.second!=-1) mp1[prec1.second]++; map<int, int> mp2; mp2[vaut[seq[empl]]]++; if (prec2.first!=-1) mp2[prec2.first]++; if (prec2.second!=-1) mp2[prec2.second]++; s1+=mp1.size(); s2+=mp2.size(); return memo[{empl, {prec1, prec2}}]=max(s1, s2); } void solve() { vaut['M']=0, vaut['F']=1, vaut['B']=2; cin >> n; cin >> seq; memo.clear(); cout << dp(0, {-1, -1}, {-1, -1}) << endl; return; } signed main() { ios::sync_with_stdio(0); cin.tie(0); int tt=1;// cin >> tt; while(tt--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...