제출 #1243027

#제출 시각아이디문제언어결과실행 시간메모리
1243027edga1Miners (IOI07_miners)C++20
100 / 100
479 ms652 KiB
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;
struct state{
    int p1;
    int p2;
    int o1;
    int o2;
    bool operator=(const state &a) const{
        return a.p1==p1 && a.p2==p2 && a.o1==o1 && a.o2==o2;
    }
    bool operator<(const state &a) const{
        if(a.p1!=p1) return a.p1<p1;
        if(a.p2!=p2) return a.p2<p2;
        if(a.o1!=o1) return a.o1<o1;
        return a.o2<o2;
    }
};
//M=1,B=2,F=3

int main(){
    FIO
    int n;
    string s;
    cin>>n>>s;
    map<state,int> cu,ne;
    cu[{0,0,0,0}]=0;
    for(int i=0; i<n; i++){
        char c=s[i];
        int sk;
        if(c=='M') sk=1;
        if(c=='B') sk=2;
        if(c=='F') sk=3;
        for(auto a : cu){
            state st=a.fi;
            int r=a.se,r1=1,r2=1;
            if(st.p1==0) r1=1;
            else if(st.p2==0){
                if(st.p1!=sk) r1=2;
            }else{
                if(sk!=st.p1 || sk!=st.p2 || st.p1!=st.p2) r1=2;
                if(sk!=st.p1 && sk!=st.p2 && st.p1!=st.p2) r1=3;
            }
            if(st.o1==0) r2=1;
            else if(st.o2==0){
                if(st.o1!=sk) r2=2;
            }else{
                if(sk!=st.o1 || sk!=st.o2 || st.o1!=st.o2) r2=2;
                if(sk!=st.o1 && sk!=st.o2 && st.o1!=st.o2) r2=3;
            }
            ne[{sk,st.p1,st.o1,st.o2}]=max(ne[{sk,st.p1,st.o1,st.o2}],r+r1);
            ne[{st.p1,st.p2,sk,st.o1}]=max(ne[{st.p1,st.p2,sk,st.o1}],r+r2);
        }
        cu.clear();
        for(auto a : ne){
            cu[a.fi]=a.se;
        }
        ne.clear();
    }
    int atb=0;
    for(auto a : cu){
        atb=max(atb,a.se);
    }
    cout<<atb;
    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...