Submission #127697

# Submission time Handle Problem Language Result Execution time Memory
127697 2019-07-10T02:26:26 Z arnold518 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
146 ms 163100 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 400;
const int INF = 1000000;

int N, ans;
char S[MAXN+10];

int dp[MAXN+10][MAXN+10][MAXN+10][3];
int rcnt[MAXN+10], gcnt[MAXN+10], ycnt[MAXN+10];
vector<int> rpos, gpos, ypos;

int main()
{
    int i, j;

    scanf("%d%s", &N, S+1);
    for(i=1; i<=N; i++)
    {
        rcnt[i]=rcnt[i-1]; gcnt[i]=gcnt[i-1]; ycnt[i]=ycnt[i-1];
        if(S[i]=='R') rpos.push_back(i), rcnt[i]++;
        if(S[i]=='G') gpos.push_back(i), gcnt[i]++;
        if(S[i]=='Y') ypos.push_back(i), ycnt[i]++;
        //printf("%d %d %d\n", rcnt[i], gcnt[i], ycnt[i]);
    }

    for(int r=0; r<=rpos.size(); r++)
    {
        for(int g=0; g<=gpos.size(); g++)
        {
            for(int y=0; y<=ypos.size(); y++)
            {
                dp[r][g][y][0]=dp[r][g][y][1]=dp[r][g][y][2]=INF;
                if(r==0 && g==0 && y==0)
                {
                    dp[r][g][y][0]=dp[r][g][y][1]=dp[r][g][y][2]=0;
                    continue;
                }
                int pos=r+g+y;
                if(r!=0) dp[r][g][y][0]=min(dp[r-1][g][y][1], dp[r-1][g][y][2])+max(0, gcnt[rpos[r-1]]-g)+max(0, ycnt[rpos[r-1]]-y);
                if(g!=0) dp[r][g][y][1]=min(dp[r][g-1][y][0], dp[r][g-1][y][2])+max(0, rcnt[gpos[g-1]]-r)+max(0, ycnt[gpos[g-1]]-y);
                if(y!=0) dp[r][g][y][2]=min(dp[r][g][y-1][0], dp[r][g][y-1][1])+max(0, rcnt[ypos[y-1]]-r)+max(0, gcnt[ypos[y-1]]-g);
                //printf("%d %d %d : %d %d %d\n", r, g, y, dp[r][g][y][0], dp[r][g][y][1], dp[r][g][y][2]);
            }
        }
    }
    ans=min(min(dp[rpos.size()][gpos.size()][ypos.size()][0], dp[rpos.size()][gpos.size()][ypos.size()][1]), dp[rpos.size()][gpos.size()][ypos.size()][2]);
    if(ans>=INF) ans=-1;
    printf("%d", ans);
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:32:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int r=0; r<=rpos.size(); r++)
                  ~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:34:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int g=0; g<=gpos.size(); g++)
                      ~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:36:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int y=0; y<=ypos.size(); y++)
                          ~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:44:21: warning: unused variable 'pos' [-Wunused-variable]
                 int pos=r+g+y;
                     ^~~
joi2019_ho_t3.cpp:20:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
joi2019_ho_t3.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%s", &N, S+1);
     ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 3 ms 2424 KB Output is correct
19 Correct 3 ms 1912 KB Output is correct
20 Correct 3 ms 2296 KB Output is correct
21 Correct 4 ms 2428 KB Output is correct
22 Correct 3 ms 1656 KB Output is correct
23 Correct 3 ms 2172 KB Output is correct
24 Correct 3 ms 1656 KB Output is correct
25 Correct 6 ms 3960 KB Output is correct
26 Correct 7 ms 4216 KB Output is correct
27 Correct 5 ms 3064 KB Output is correct
28 Correct 4 ms 2424 KB Output is correct
29 Correct 4 ms 2296 KB Output is correct
30 Correct 5 ms 2300 KB Output is correct
31 Correct 3 ms 2040 KB Output is correct
32 Correct 4 ms 2428 KB Output is correct
33 Correct 5 ms 3832 KB Output is correct
34 Correct 4 ms 3576 KB Output is correct
35 Correct 4 ms 2680 KB Output is correct
36 Correct 4 ms 1912 KB Output is correct
37 Correct 4 ms 1784 KB Output is correct
38 Correct 4 ms 2168 KB Output is correct
39 Correct 4 ms 2424 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 3 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 129 ms 163000 KB Output is correct
3 Correct 142 ms 162220 KB Output is correct
4 Correct 146 ms 162964 KB Output is correct
5 Correct 121 ms 163068 KB Output is correct
6 Correct 119 ms 162944 KB Output is correct
7 Correct 119 ms 162140 KB Output is correct
8 Correct 118 ms 162404 KB Output is correct
9 Correct 118 ms 161400 KB Output is correct
10 Correct 120 ms 163052 KB Output is correct
11 Correct 121 ms 163100 KB Output is correct
12 Correct 33 ms 44024 KB Output is correct
13 Correct 58 ms 77148 KB Output is correct
14 Correct 81 ms 111480 KB Output is correct
15 Correct 120 ms 163064 KB Output is correct
16 Correct 120 ms 163064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 3 ms 2424 KB Output is correct
19 Correct 3 ms 1912 KB Output is correct
20 Correct 3 ms 2296 KB Output is correct
21 Correct 4 ms 2428 KB Output is correct
22 Correct 3 ms 1656 KB Output is correct
23 Correct 3 ms 2172 KB Output is correct
24 Correct 3 ms 1656 KB Output is correct
25 Correct 6 ms 3960 KB Output is correct
26 Correct 7 ms 4216 KB Output is correct
27 Correct 5 ms 3064 KB Output is correct
28 Correct 4 ms 2424 KB Output is correct
29 Correct 4 ms 2296 KB Output is correct
30 Correct 5 ms 2300 KB Output is correct
31 Correct 3 ms 2040 KB Output is correct
32 Correct 4 ms 2428 KB Output is correct
33 Correct 5 ms 3832 KB Output is correct
34 Correct 4 ms 3576 KB Output is correct
35 Correct 4 ms 2680 KB Output is correct
36 Correct 4 ms 1912 KB Output is correct
37 Correct 4 ms 1784 KB Output is correct
38 Correct 4 ms 2168 KB Output is correct
39 Correct 4 ms 2424 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 3 ms 2168 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 129 ms 163000 KB Output is correct
44 Correct 142 ms 162220 KB Output is correct
45 Correct 146 ms 162964 KB Output is correct
46 Correct 121 ms 163068 KB Output is correct
47 Correct 119 ms 162944 KB Output is correct
48 Correct 119 ms 162140 KB Output is correct
49 Correct 118 ms 162404 KB Output is correct
50 Correct 118 ms 161400 KB Output is correct
51 Correct 120 ms 163052 KB Output is correct
52 Correct 121 ms 163100 KB Output is correct
53 Correct 33 ms 44024 KB Output is correct
54 Correct 58 ms 77148 KB Output is correct
55 Correct 81 ms 111480 KB Output is correct
56 Correct 120 ms 163064 KB Output is correct
57 Correct 120 ms 163064 KB Output is correct
58 Correct 77 ms 77232 KB Output is correct
59 Correct 91 ms 97796 KB Output is correct
60 Correct 85 ms 88952 KB Output is correct
61 Correct 83 ms 85884 KB Output is correct
62 Correct 119 ms 160760 KB Output is correct
63 Correct 120 ms 160400 KB Output is correct
64 Correct 120 ms 150136 KB Output is correct
65 Correct 123 ms 138488 KB Output is correct
66 Correct 83 ms 87160 KB Output is correct
67 Correct 80 ms 83960 KB Output is correct
68 Correct 85 ms 89848 KB Output is correct
69 Correct 84 ms 86572 KB Output is correct
70 Correct 88 ms 93688 KB Output is correct
71 Correct 82 ms 85092 KB Output is correct
72 Correct 37 ms 42104 KB Output is correct
73 Correct 5 ms 2940 KB Output is correct