답안 #901660

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
901660 2024-01-09T21:52:30 Z jay_jayjay Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()

#define infl 0x3f3f3f3f3f3f3f3f
#define ll long long

#define N 400

int n;
char s[N+1];
int pos[3][N+1];

//ll dp[N+1][N+1][N+1][3];

template<typename T> void chmin(T& x, T y) { x=min(x,y); }

int main()
{
        scanf("%d %s",&n,s);
        for(auto&x:s) x = x=='R'?0:x=='G'?1:x=='Y'?2:-1;

        int c[3]={0,0,0};
        for(int i=0;i<n;i++) {
                pos[s[i]][c[s[i]]]=i;
                c[s[i]]++;
        }

        vector dp(c[0]+1,vector(c[1]+1,vector(c[2]+1,vector<ll>(3,infl))));

        //memset(dp,0x3f,sizeof(dp));
        for(int k=0;k<3;k++) dp[0][0][0][k]=0;
        for(int i0=0;i0<=c[0];i0++)
                for(int i1=0;i1<=c[1];i1++)
                        for(int i2=0;i2<=c[2];i2++) {
                                for(int j=0;j<3;j++) {
                                        int p = i0+i1+i2;
                                        ll v=dp[i0][i1][i2][j];
                                        //printf("dp %d %d %d %c = %d\n",i0,i1,i2,j+'a',v);
                                        for(int k=0;k<3;k++) if(j!=k) {
                                                int i[3]={i0,i1,i2};
                                                i[k]++;
                                                //printf("\t\t\t-> %d %d %d %c : %d\n",i[0],i[1],i[2],k+'a',v+abs(pos[k][i[k]-1]-p));
                                                for(int ii=0;ii<3;ii++)if(i[ii]>c[ii])goto dont;
                                                chmin(dp[i[0]][i[1]][i[2]][k],v+abs(pos[k][i[k]-1]-p));
                                                dont:;
                                        }
                                }
        }
        ll mn = infl;
        for(int k=0;k<3;k++) chmin(mn,dp[c[0]][c[1]][c[2]][k]/2);
        printf("%lld\n",mn);
}
// then to optimize this, we can consider trying everything at once
// so dp[ra][ga][ba][current symbol] will trivialize this
// why didn't i think of this hadsfhlaksdhflkasdjalkfjslkdajflkadsj

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:25:24: warning: array subscript has type 'char' [-Wchar-subscripts]
   25 |                 pos[s[i]][c[s[i]]]=i;
      |                     ~~~^
joi2019_ho_t3.cpp:25:32: warning: array subscript has type 'char' [-Wchar-subscripts]
   25 |                 pos[s[i]][c[s[i]]]=i;
      |                             ~~~^
joi2019_ho_t3.cpp:26:22: warning: array subscript has type 'char' [-Wchar-subscripts]
   26 |                 c[s[i]]++;
      |                   ~~~^
joi2019_ho_t3.cpp:29:16: error: missing template arguments before 'dp'
   29 |         vector dp(c[0]+1,vector(c[1]+1,vector(c[2]+1,vector<ll>(3,infl))));
      |                ^~
joi2019_ho_t3.cpp:32:30: error: 'dp' was not declared in this scope
   32 |         for(int k=0;k<3;k++) dp[0][0][0][k]=0;
      |                              ^~
joi2019_ho_t3.cpp:38:46: error: 'dp' was not declared in this scope; did you mean 'p'?
   38 |                                         ll v=dp[i0][i1][i2][j];
      |                                              ^~
      |                                              p
joi2019_ho_t3.cpp:51:39: error: 'dp' was not declared in this scope
   51 |         for(int k=0;k<3;k++) chmin(mn,dp[c[0]][c[1]][c[2]][k]/2);
      |                                       ^~
joi2019_ho_t3.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         scanf("%d %s",&n,s);
      |         ~~~~~^~~~~~~~~~~~~~