제출 #353651

#제출 시각아이디문제언어결과실행 시간메모리
353651SavicSMiners (IOI07_miners)C++14
100 / 100
98 ms1000 KiB
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define ff(i,a,b) for(int i=a;i<=b;i++) #define fb(i,b,a) for(int i=b;i>=a;i--) using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair<int,int> pii; const int maxn = 100005; const int inf = 1e9 + 5; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // os.order_of_key(k) the number of elements in the os less than k // *os.find_by_order(k) print the k-th smallest number in os(0-based) int n; int niz[maxn]; string s; int dp[4][4][4][4]; int pomdp[4][4][4][4]; int pom[4][4][4]; int calc(int x, int y, int z){ set<int> poms; if(x)poms.insert(x); if(y)poms.insert(y); if(z)poms.insert(z); return sz(poms); } int main() { ios::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr); cin >> n >> s; s = ' ' + s; ff(i,1,n)niz[i] = (s[i] == 'M' ? 1 : (s[i] == 'B' ? 2 : 3)); ff(a,0,3)ff(b,0,3)ff(c,0,3)ff(d,0,3)dp[a][b][c][d] = -inf; ff(a,0,3)ff(b,0,3)ff(c,0,3)pom[a][b][c] = calc(a, b, c); dp[0][0][0][0] = 0; ff(i,1,n){ ff(a,0,3)ff(b,0,3)ff(c,0,3)ff(d,0,3)pomdp[a][b][c][d] = -inf; int x = niz[i]; ff(a,0,3){ ff(b,0,3){ ff(c,0,3){ ff(d,0,3){ pomdp[a][b][d][x] = max(pomdp[a][b][d][x], dp[a][b][c][d] + pom[c][d][x]); pomdp[b][x][c][d] = max(pomdp[b][x][c][d], dp[a][b][c][d] + pom[a][b][x]); } } } } ff(a,0,3)ff(b,0,3)ff(c,0,3)ff(d,0,3)dp[a][b][c][d] = pomdp[a][b][c][d]; } int rez = -inf; ff(a,0,3){ ff(b,0,3){ ff(c,0,3){ ff(d,0,3)rez = max(rez, dp[a][b][c][d]); } } } cout << rez << endl; return 0; } /** 6 MBMFFB 16 MMBMBBBBMMMMMBMB // probati bojenje sahovski ili slicno **/
#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...