Submission #672442

#TimeUsernameProblemLanguageResultExecution timeMemory
672442sudheerays123Miners (IOI07_miners)C++17
34 / 100
1 ms844 KiB
#include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define ll long long int const ll N = 100+5 , INF = 1e18 , MOD = 1e9+7; vector<ll> mine1,mine2; ll dp[N][(1ll<<4)][(1ll<<4)]; ll n; string s; ll chartoll(char x){ if(x == 'M') return 0; else if(x == 'B') return 1; return 2; } ll go(ll i , ll mask1 , ll mask2){ if(i == n+1) return 0; if(dp[i][mask1][mask2] != -1) return dp[i][mask1][mask2]; ll ans = 0; ll curmask1 = mask1; curmask1 |= (1ll<<(chartoll(s[i]))); ll c1 = __builtin_popcount(curmask1); ll newmask1 = (1ll<<(chartoll(s[i]))); if(mine1.size() >= 1){ ll x = mine1[mine1.size()-1]; newmask1 |= (1ll<<x); } mine1.push_back(chartoll(s[i])); ans = max(ans,c1+go(i+1,newmask1,mask2)); mine1.pop_back(); ll curmask2 = mask2; curmask2 |= (1ll<<(chartoll(s[i]))); ll c2 = __builtin_popcount(curmask2); ll newmask2 = (1ll<<(chartoll(s[i]))); if(mine2.size() >= 1){ ll x = mine2[mine2.size()-1]; newmask2 |= (1ll<<x); } mine2.push_back(chartoll(s[i])); ans = max(ans,c2+go(i+1,mask1,newmask2)); mine2.pop_back(); return dp[i][mask1][mask2] = ans; } void solve(){ cin >> n >> s; s = ' '+s; memset(dp,-1,sizeof dp); cout << go(1,0,0); } int main(){ fast; ll tc = 1; // cin >> tc; while(tc--) 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...