이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 = 1e5+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 = -INF;
ll curmask = mask1;
curmask |= (1ll<<chartoll(s[i]));
ll c1 = __builtin_popcount(curmask);
ll newmask1 = (1ll<<chartoll(s[i]));
if(mine1.size() >= 1) newmask1 |= (1ll<<mine1[mine1.back()]);
mine1.push_back(chartoll(s[i]));
ans = max(ans,c1+go(i+1,newmask1,mask2));
mine1.pop_back();
curmask = mask2;
curmask |= (1ll<<chartoll(s[i]));
ll c2 = __builtin_popcount(curmask);
ll newmask2 = (1ll<<chartoll(s[i]));
if(mine2.size() >= 1) newmask2 |= (1ll<<mine2[mine2.back()]);
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)-1;
}
int main(){
fast;
ll tc = 1;
// cin >> tc;
while(tc--) 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... |