답안 #866782

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
866782 2023-10-27T04:01:17 Z 12345678 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
100 / 100
35 ms 28764 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=405;
int n, mp[100], qs[3][nx], r[3][nx], res=INT_MAX;
string s;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>s;
    mp['R']=0; mp['G']=1; mp['Y']=2;
    for (int i=1; i<=n; i++)
    {
        for (int j=0; j<3; j++) qs[j][i]=qs[j][i-1];
        qs[mp[s[i-1]]][i]++;
        r[mp[s[i-1]]][qs[mp[s[i-1]]][i]]=i;
    }
    int dp[qs[0][n]+1][qs[1][n]+1][qs[2][n]+1][3];
    //for (int i=1; i<=n; i++) cout<<i<<' '<<qs[0][i]<<' '<<qs[1][i]<<' '<<qs[2][i]<<'\n';
    //for (int i=1; i<=n; i++) cout<<i<<' '<<r[0][i]<<' '<<r[1][i]<<' '<<r[2][i]<<'\n';
    for (int i=0; i<=qs[0][n]; i++)
    {
        for (int j=0; j<=qs[1][n]; j++)
        {
            for (int k=0; k<=qs[2][n]; k++)
            {
                dp[i][j][k][0]=dp[i][j][k][1]=dp[i][j][k][2]=1e6;
                if (i==0&&j==0&&k==0) dp[i][j][k][0]=dp[i][j][k][1]=dp[i][j][k][2]=0;
                if (i>0) 
                {
                    int c=r[0][i], f1=qs[1][c], f2=qs[2][c], cst=0;
                    if (f1>j) cst+=f1-j;
                    if (f2>k) cst+=f2-k;
                    dp[i][j][k][0]=min({dp[i-1][j][k][1]+cst, dp[i-1][j][k][2]+cst, dp[i][j][k][0]});
                }
                if (j>0)
                {
                    int c=r[1][j], f1=qs[0][c], f2=qs[2][c], cst=0;
                    if (f1>i) cst+=f1-i;
                    if (f2>k) cst+=f2-k;
                    dp[i][j][k][1]=min({dp[i][j-1][k][0]+cst, dp[i][j-1][k][2]+cst, dp[i][j][k][1]});
                }
                if (k>0)
                {
                    int c=r[2][k], f1=qs[0][c], f2=qs[1][c], cst=0;
                    if (f1>i) cst+=f1-i;
                    if (f2>j) cst+=f2-j;
                    //cout<<"here"<<' '<<cst<<' '<<c<<'\n';
                    dp[i][j][k][2]=min({dp[i][j][k-1][0]+cst, dp[i][j][k-1][1]+cst, dp[i][j][k][2]});
                }
                //cout<<i<<' '<<j<<' '<<k<<' '<<dp[i][j][k][0]<<' '<<dp[i][j][k][1]<<' '<<dp[i][j][k][2]<<'\n';
            }
        }
    }
    for (int i=0; i<3; i++) res=min(res, dp[qs[0][n]][qs[1][n]][qs[2][n]][i]);
    if (res==1e6) cout<<-1;
    else cout<<res;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:17:21: warning: array subscript has type 'char' [-Wchar-subscripts]
   17 |         qs[mp[s[i-1]]][i]++;
      |                     ^
joi2019_ho_t3.cpp:18:20: warning: array subscript has type 'char' [-Wchar-subscripts]
   18 |         r[mp[s[i-1]]][qs[mp[s[i-1]]][i]]=i;
      |                    ^
joi2019_ho_t3.cpp:18:35: warning: array subscript has type 'char' [-Wchar-subscripts]
   18 |         r[mp[s[i-1]]][qs[mp[s[i-1]]][i]]=i;
      |                                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 1 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 860 KB Output is correct
44 Correct 1 ms 860 KB Output is correct
45 Correct 1 ms 860 KB Output is correct
46 Correct 1 ms 860 KB Output is correct
47 Correct 1 ms 860 KB Output is correct
48 Correct 1 ms 860 KB Output is correct
49 Correct 1 ms 860 KB Output is correct
50 Correct 1 ms 860 KB Output is correct
51 Correct 1 ms 860 KB Output is correct
52 Correct 1 ms 860 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 600 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 860 KB Output is correct
57 Correct 1 ms 856 KB Output is correct
58 Correct 33 ms 28504 KB Output is correct
59 Correct 34 ms 28508 KB Output is correct
60 Correct 32 ms 28252 KB Output is correct
61 Correct 34 ms 28508 KB Output is correct
62 Correct 3 ms 2648 KB Output is correct
63 Correct 5 ms 4444 KB Output is correct
64 Correct 18 ms 14172 KB Output is correct
65 Correct 23 ms 20316 KB Output is correct
66 Correct 35 ms 28252 KB Output is correct
67 Correct 33 ms 28252 KB Output is correct
68 Correct 33 ms 28508 KB Output is correct
69 Correct 33 ms 28760 KB Output is correct
70 Correct 34 ms 28764 KB Output is correct
71 Correct 33 ms 28152 KB Output is correct
72 Correct 9 ms 7424 KB Output is correct
73 Correct 3 ms 2136 KB Output is correct