답안 #535030

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
535030 2022-03-09T10:31:27 Z __Variatto Crtanje (COCI20_crtanje) C++17
0 / 50
1 ms 332 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define ll long long
const int MAX=1e5+10;
int n, dp[MAX][4][4][4][4], t[MAX];
string s;
int rozne(int a, int b, int c){
    if(!c&&!b)
        return 1;
    if(!c){
        if(b==a)
            return 1;
        else
            return 2;
    }
    if(a==b&&b==c)
        return 1;
    else if(a==b||b==c||c==a)
        return 2;
    else
        return 3;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>n>>s;
    for(int i=1; i<=n; i++){
        if(s[i-1]=='M') t[i]=1;
        if(s[i-1]=='B') t[i]=2;
        if(s[i-1]=='F') t[i]=3;
    }
    for(int a=0; a<=3; a++)
        for(int b=0; b<=3; b++)
            for(int c=0; c<=3; c++)
                for(int d=0; d<=3; d++)
                    dp[0][a][b][c][d]=-1;
    dp[0][0][0][0][0]=0;
    for(int i=1; i<=n; i++){
        for(int a=0; a<=3; a++)
            for(int b=0; b<=3; b++)
                for(int c=0; c<=3; c++)
                    for(int d=0; d<=3; d++)
                        dp[i][a][b][c][d]=-1;
        for(int a=0; a<=3; a++){
            for(int c=0; c<=3; c++){
                for(int d=0; d<=3; d++){
                    for(int b=0; b<=3; b++){
                        if(dp[i-1][a][b][c][d]==-1)
                            continue;
                        dp[i][t[i]][a][c][d]=max(dp[i][t[i]][a][c][d], dp[i-1][a][b][c][d]+rozne(t[i], a, b));
                    }
                }
            }
        }
        for(int a=0; a<=3; a++){
            for(int b=0; b<=3; b++){
                for(int d=0; d<=3; d++){
                    for(int c=0; c<=3; c++){
                        if(dp[i-1][a][b][c][d]==-1)
                            continue;
                        dp[i][a][b][t[i]][c]=max(dp[i][a][b][t[i]][c], dp[i-1][a][b][c][d]+rozne(t[i], c, d));
                    }
                }
            }
        }
    }
    int maxi=0;
    for(int a=0; a<=3; a++)
        for(int b=0; b<=3; b++)
            for(int c=0; c<=3; c++)
                for(int d=0; d<=3; d++)
                    maxi=max(maxi, dp[n][a][b][c][d]);
    cout<<maxi<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Incorrect 0 ms 332 KB Output isn't correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Incorrect 1 ms 320 KB Output isn't correct