Submission #483583

# Submission time Handle Problem Language Result Execution time Memory
483583 2021-10-31T02:35:50 Z TLP39 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
198 ms 96436 KB
#include<bits/stdc++.h>
using namespace std;
 
int l;
char s[402];
int nR=0,nG=0,nY=0;
int pos[3][402];
int acc[402][3];

void init()
{
    scanf("%d ",&l);
    scanf("%s",s);
    acc[0][0]=acc[0][1]=acc[0][2]=0;
    for(int i=0;i<l;i++)
    {
        if(i)
        {
            acc[i][0]=acc[i-1][0];
            acc[i][1]=acc[i-1][1];
            acc[i][2]=acc[i-1][2];
        }
        if(s[i]=='R')
        {
            pos[0][nR]=i;
            acc[i][0]++;
            nR++;
        }
        else if(s[i]=='G')
        {
            pos[1][nG]=i;
            acc[i][1]++;
            nG++;
        }
        else
        {
            pos[2][nY]=i;
            acc[i][2]++;
            nY++;
        }
    }
}
int dp[202][202][202][3];
int MAX_INT = 1900000000;

int solve(int arr[],int typ)
{
    if(dp[arr[0]][arr[1]][arr[2]][typ]>=0) return dp[arr[0]][arr[1]][arr[2]][typ];
    int arr_copy[3]={arr[0],arr[1],arr[2]};
    if(arr_copy[typ]==0) return dp[arr[0]][arr[1]][arr[2]][typ] = MAX_INT;
    arr_copy[typ]--;
    int carry = 0;
    for(int i=0;i<3;i++)
    {
        if(i==typ) continue;
        carry += max(0,arr_copy[i]-acc[pos[typ][arr_copy[typ]]][i]);
    }
    int dpBefore = MAX_INT;
    for(int i=0;i<3;i++)
    {
        if(i==typ) continue;
        dpBefore = min(dpBefore,solve(arr_copy,i));
    }
    return dp[arr[0]][arr[1]][arr[2]][typ] = dpBefore+carry;
}

int main()
{
    init();
    if(max(nR,max(nG,nY)) > (l+1)/2)
    {
        printf("-1");
        return 0;
    }
    for(int i1=0;i1<=nR;i1++)
    {
        for(int i2=0;i2<=nG;i2++)
        {
            for(int i3=0;i3<=nY;i3++)
            {
                dp[i1][i2][i3][0]=dp[i1][i2][i3][1]=dp[i1][i2][i3][2]=-1;
            }
        }
    }
    dp[0][0][0][0]=dp[0][0][0][1]=dp[0][0][0][2]=0;
    for(int i1=0;i1<=nR;i1++)
    {
        for(int i2=0;i2<=nG;i2++)
        {
            for(int i3=0;i3<=nY;i3++)
            {
                int arr[3] = {i1,i2,i3};
                solve(arr,0);
                solve(arr,1);
                solve(arr,2);
            }
        }
    }
    printf("%d",min(dp[nR][nG][nY][0],min(dp[nR][nG][nY][1],dp[nR][nG][nY][2])));
}

Compilation message

joi2019_ho_t3.cpp: In function 'void init()':
joi2019_ho_t3.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%d ",&l);
      |     ~~~~~^~~~~~~~~~
joi2019_ho_t3.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%s",s);
      |     ~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 1356 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 2 ms 1356 KB Output is correct
21 Correct 2 ms 1452 KB Output is correct
22 Correct 1 ms 972 KB Output is correct
23 Correct 1 ms 1228 KB Output is correct
24 Correct 1 ms 972 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 2 ms 1868 KB Output is correct
28 Correct 1 ms 1356 KB Output is correct
29 Correct 2 ms 1356 KB Output is correct
30 Correct 1 ms 1356 KB Output is correct
31 Correct 2 ms 1196 KB Output is correct
32 Correct 1 ms 1484 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 2 ms 1612 KB Output is correct
36 Correct 2 ms 1100 KB Output is correct
37 Correct 1 ms 1100 KB Output is correct
38 Correct 2 ms 1228 KB Output is correct
39 Correct 1 ms 1356 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 38 ms 96400 KB Output is correct
3 Correct 38 ms 95948 KB Output is correct
4 Correct 38 ms 96436 KB Output is correct
5 Correct 37 ms 96428 KB Output is correct
6 Correct 47 ms 96376 KB Output is correct
7 Correct 43 ms 96004 KB Output is correct
8 Correct 46 ms 95900 KB Output is correct
9 Correct 38 ms 95428 KB Output is correct
10 Correct 38 ms 96424 KB Output is correct
11 Correct 38 ms 96328 KB Output is correct
12 Correct 10 ms 26096 KB Output is correct
13 Correct 19 ms 45744 KB Output is correct
14 Correct 27 ms 65860 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 1356 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 2 ms 1356 KB Output is correct
21 Correct 2 ms 1452 KB Output is correct
22 Correct 1 ms 972 KB Output is correct
23 Correct 1 ms 1228 KB Output is correct
24 Correct 1 ms 972 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 2 ms 1868 KB Output is correct
28 Correct 1 ms 1356 KB Output is correct
29 Correct 2 ms 1356 KB Output is correct
30 Correct 1 ms 1356 KB Output is correct
31 Correct 2 ms 1196 KB Output is correct
32 Correct 1 ms 1484 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 2 ms 1612 KB Output is correct
36 Correct 2 ms 1100 KB Output is correct
37 Correct 1 ms 1100 KB Output is correct
38 Correct 2 ms 1228 KB Output is correct
39 Correct 1 ms 1356 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 0 ms 332 KB Output is correct
43 Correct 38 ms 96400 KB Output is correct
44 Correct 38 ms 95948 KB Output is correct
45 Correct 38 ms 96436 KB Output is correct
46 Correct 37 ms 96428 KB Output is correct
47 Correct 47 ms 96376 KB Output is correct
48 Correct 43 ms 96004 KB Output is correct
49 Correct 46 ms 95900 KB Output is correct
50 Correct 38 ms 95428 KB Output is correct
51 Correct 38 ms 96424 KB Output is correct
52 Correct 38 ms 96328 KB Output is correct
53 Correct 10 ms 26096 KB Output is correct
54 Correct 19 ms 45744 KB Output is correct
55 Correct 27 ms 65860 KB Output is correct
56 Correct 0 ms 204 KB Output is correct
57 Correct 0 ms 204 KB Output is correct
58 Correct 177 ms 38284 KB Output is correct
59 Correct 179 ms 48552 KB Output is correct
60 Correct 185 ms 44192 KB Output is correct
61 Correct 168 ms 42712 KB Output is correct
62 Correct 0 ms 204 KB Output is correct
63 Correct 58 ms 92680 KB Output is correct
64 Correct 109 ms 80960 KB Output is correct
65 Correct 155 ms 70464 KB Output is correct
66 Correct 163 ms 43328 KB Output is correct
67 Correct 171 ms 41684 KB Output is correct
68 Correct 171 ms 44624 KB Output is correct
69 Correct 175 ms 43004 KB Output is correct
70 Correct 198 ms 46520 KB Output is correct
71 Correct 169 ms 42344 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 0 ms 204 KB Output is correct