Submission #274627

#TimeUsernameProblemLanguageResultExecution timeMemory
274627FalconMiners (IOI07_miners)C++14
100 / 100
1301 ms160888 KiB
#pragma GCC optimize("O2") #include <bits/stdc++.h> #ifdef DEBUG #include "debug.hpp" #endif using namespace std; #define all(c) (c).begin(), (c).end() #define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); it++) #define rep(i, N) for(int i = 0; i < (N); i++) #define rep1(i, N) for(int i = 1; i <= (N); i++) #define rep2(i, s, e) for(int i = (s); i <= (e); i++) #define rep3(i, s, e, d) for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d)) #define pb push_back #ifdef DEBUG #define debug(x...) {dbg::depth++; string dbg_vals = dbg::to_string(x); dbg::depth--; dbg::fprint(__func__, __LINE__, #x, dbg_vals);} #define light_debug(x) {dbg::light = 1; dbg::dout << __func__ << ":" << __LINE__ << " " << #x << " = " << x << endl; dbg::light = 0;} #else #define debug(x...) #define light_debug(x) #endif template<typename T> T& ckmin(T& a, T b){ return a = a > b ? b : a; } template<typename T> T& ckmax(T& a, T b){ return a = a < b ? b : a; } using ll = long long; using pii = pair<int, int>; using vi = vector<int>; int N; string s; int dp[100000][4][4][4][4]; bool ch[100000][4][4][4][4]; map<char, int> c; int rec(int i, int a, int b, int x, int y){ if(i == N) return 0; if(ch[i][a][b][x][y]) return dp[i][a][b][x][y]; set<int> tmp = {a, b, c[s[i]]}; tmp.erase(0); int mine1 = tmp.size() + rec(i + 1, c[s[i]], a, x, y); tmp = {x, y, c[s[i]]}; tmp.erase(0); int mine2 = tmp.size() + rec(i + 1, a, b, c[s[i]], x); ch[i][a][b][x][y] = 1; return dp[i][a][b][x][y] = max(mine1, mine2); } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); #ifdef DEBUG freopen("debug", "w", stderr); #endif c['M'] = 1, c['F'] = 2, c['B'] = 3; cin >> N >> s; cout << rec(0, 0, 0, 0, 0) << '\n'; #ifdef DEBUG dbg::dout << "\nExecution time: " << clock() << "ms\n"; #endif 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...