답안 #291986

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
291986 2020-09-06T06:38:50 Z TAMREF Acrobat (balkan16_acrobat) C++11
0 / 100
0 ms 256 KB
#include<cstdio>
#include<algorithm>
using namespace std;
int TC;
int n, w[5010], D[5010][3][4], cnt, TD[5010][3][4];
int main(){
    int i, j, k, l, ii, X, Y;
    int TC = 1;
    while(TC--){
        scanf("%d %d %d",&n,&X,&Y);
        cnt = 0;
        int ck[3] = {0};
        for(i=1;i<=n;i++){
            scanf("%d",&w[i]);
            w[i] = (w[i] == X ? 0 : w[i] == Y ? 1 : 2);
            ck[w[i]] = 1;
            if(w[i] == 2)cnt++;
        }
        if(!ck[0] || !ck[1]){
            printf("0\n");
            continue;
        }
        if(ck[2] == 0){
            printf("-1\n");
            continue;
        }
        for(i=0;i<=cnt;i++){
            for(j=0;j<3;j++)for(k=0;k<4;k++)D[i][j][k]=TD[i][j][k]=-1e9;
        }
        D[0][2][0] = 0;
        for(i=1;i<=n;i++){
            for(j=0;j<=cnt;j++){
                for(k=0;k<3;k++){
                    for(ii=0;ii<4;ii++){
                        if(D[j][k][ii]<0)continue;
                        
                        for(l=0;l<3;l++){
                            int t = (l+1)%3;
                            TD[j+1][l][ii | t] = max(TD[j+1][l][ii | t], D[j][k][ii]+1);
                            if((k!=2 && k==l) || (k==2 && k!=l)){
                                TD[j][l][ii | t] = max(TD[j][l][ii | t], D[j][k][ii]+(l==w[i]));
                            }
                        }
                        TD[j][k][ii] = max(TD[j][k][ii], D[j][k][ii]);
                    }
                }
            }
            for(j=0;j<=cnt;j++){
                for(k=0;k<3;k++){
                    for(l=0;l<4;l++){
                        D[j][k][l] = TD[j][k][l];
                        TD[j][k][l] = -1e9;
                    }
                }
            }
        }
        int res = 0;
        for(i=cnt;i>=0;i--){
            for(k=0;k<3;k++){
                for(j=0;j<4;j++){
                    if(i==cnt && j!=3)continue;
                    res = max(res, D[i][k][j]);
                }
            }
        }
        printf("%d\n",n-res);
    }
}

Compilation message

main.cpp: In function 'int main()':
main.cpp:10:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |         scanf("%d %d %d",&n,&X,&Y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp:14:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |             scanf("%d",&w[i]);
      |             ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -