이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define ff first
#define ss second
#define ll long long
#define append push_back
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
set<int> x;
inline int c(int& n,int& m,int& o){
if(n) x.insert(n);
if(m) x.insert(m);
if(o) x.insert(o);
int z=x.size();
x.clear();
return z;
}
void solve(){
char s;
int n,m,o,p,q,r;
cin>>n;
map<pair<pii,pii>,int> dp,dp2;
dp[{{0,0},{0,0}}]=0;
for(int i=0;i<n;i++){
cin>>s;
if(s=='M') m=1;
if(s=='F') m=2;
if(s=='B') m=3;
for(auto& i:dp){
o=i.ff.ff.ff;
p=i.ff.ff.ss;
q=i.ff.ss.ff;
r=i.ff.ss.ss;
dp2[{{p,m},{q,r}}]=max(dp2[{{p,m},{q,r}}]
,i.ss+c(o,p,m));
dp2[{{o,p},{r,m}}]=max(dp2[{{o,p},{r,m}}]
,i.ss+c(q,r,m));
}
swap(dp,dp2);
dp2.clear();
}
o=0;
for(auto& i:dp)
o=max(o,i.ss);
cout<<o;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
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... |