답안 #670503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
670503 2022-12-09T10:53:51 Z berr Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
100 / 100
433 ms 767972 KB
#include <bits/stdc++.h>
using namespace std;    
int a[405][3][405][405]; 
array<int, 3> p[405];


signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    vector<int> b[3];

    string s; cin>>s;


    for(int l=0; l<3; l++) b[l].push_back(0);

    for(int i = 1; i <=n; i++){
        p[i]=p[i-1];
        if(s[i-1]=='R') b[0].push_back(i), p[i][0]++;
        if(s[i-1]=='Y') b[1].push_back(i), p[i][1]++;
        if(s[i-1]=='G') b[2].push_back(i), p[i][2]++;


    }


    for(int i=1; i<=n; i++){
        for(int l=0; l<3; l++){
            for(int j=0; j<=n; j++)
            {
                for(int f=0; f<=n; f++)
                {
                    a[i][l][j][f]=1e9;
                }
            }
        }
    }


    for(int l=0; l<3; l++) b[l].push_back(n+1);
    int ans=1e9;

    for(int i=1; i<=n; i++){
        for(int l=0; l<=i&&l<b[0].size()-1; l++){
            for(int j=0; j+l<=i&&j<b[1].size()-1; j++){
                int k=i-(j+l);
                if(k<b[2].size()-1)
                for(int t=0; t<3; t++){
                    int dist=0;

                    int f=0;
                    if(t==0) f=l;
                    else if(t==1) f=j;
                    else f=k;

                    dist+=max(0, p[b[t][f]][0]-l);
                    dist+=max(0, p[b[t][f]][1]-j);
                    dist+=max(0, p[b[t][f]][2]-k);


                    for(int g=0; g<3&&f; g++){
                        if(t==0&&g!=t&&(l>0||i==1))
                        a[i][t][l][j]=min(a[i-1][g][max(0, l-1)][j]+dist, a[i][t][l][j]);
                        if(t==1&&g!=t&&(j>0||i==1))
                        a[i][t][l][j]=min(a[i-1][g][l][max(0, j-1)]+dist, a[i][t][l][j]);
                        if(t==2&&g!=t&&(k>0||i==1))
                        a[i][t][l][j]=min(a[i-1][g][l][j]+dist, a[i][t][l][j]);
                    
                    }

                    if(i==n) ans=min(ans, a[i][t][l][j]);
                }


            }
    
        }
    }



    if(ans>=1e9) cout<<-1;
    else cout<<ans;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:45:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for(int l=0; l<=i&&l<b[0].size()-1; l++){
      |                            ~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:46:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |             for(int j=0; j+l<=i&&j<b[1].size()-1; j++){
      |                                  ~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:48:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |                 if(k<b[2].size()-1)
      |                    ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 852 KB Output is correct
5 Correct 1 ms 1620 KB Output is correct
6 Correct 1 ms 1620 KB Output is correct
7 Correct 1 ms 1620 KB Output is correct
8 Correct 1 ms 1620 KB Output is correct
9 Correct 1 ms 1528 KB Output is correct
10 Correct 1 ms 1620 KB Output is correct
11 Correct 1 ms 1620 KB Output is correct
12 Correct 1 ms 1620 KB Output is correct
13 Correct 1 ms 1620 KB Output is correct
14 Correct 1 ms 1364 KB Output is correct
15 Correct 1 ms 1620 KB Output is correct
16 Correct 1 ms 1620 KB Output is correct
17 Correct 1 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 852 KB Output is correct
5 Correct 1 ms 1620 KB Output is correct
6 Correct 1 ms 1620 KB Output is correct
7 Correct 1 ms 1620 KB Output is correct
8 Correct 1 ms 1620 KB Output is correct
9 Correct 1 ms 1528 KB Output is correct
10 Correct 1 ms 1620 KB Output is correct
11 Correct 1 ms 1620 KB Output is correct
12 Correct 1 ms 1620 KB Output is correct
13 Correct 1 ms 1620 KB Output is correct
14 Correct 1 ms 1364 KB Output is correct
15 Correct 1 ms 1620 KB Output is correct
16 Correct 1 ms 1620 KB Output is correct
17 Correct 1 ms 1364 KB Output is correct
18 Correct 8 ms 18388 KB Output is correct
19 Correct 8 ms 18388 KB Output is correct
20 Correct 10 ms 18516 KB Output is correct
21 Correct 8 ms 18388 KB Output is correct
22 Correct 8 ms 18388 KB Output is correct
23 Correct 8 ms 18360 KB Output is correct
24 Correct 8 ms 18388 KB Output is correct
25 Correct 8 ms 18348 KB Output is correct
26 Correct 7 ms 18388 KB Output is correct
27 Correct 9 ms 18388 KB Output is correct
28 Correct 8 ms 18292 KB Output is correct
29 Correct 8 ms 18388 KB Output is correct
30 Correct 9 ms 18400 KB Output is correct
31 Correct 9 ms 18456 KB Output is correct
32 Correct 9 ms 18360 KB Output is correct
33 Correct 8 ms 17748 KB Output is correct
34 Correct 8 ms 17748 KB Output is correct
35 Correct 8 ms 17236 KB Output is correct
36 Correct 8 ms 17748 KB Output is correct
37 Correct 8 ms 16596 KB Output is correct
38 Correct 9 ms 18388 KB Output is correct
39 Correct 8 ms 18388 KB Output is correct
40 Correct 8 ms 17748 KB Output is correct
41 Correct 8 ms 18388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 375 ms 767876 KB Output is correct
3 Correct 340 ms 764056 KB Output is correct
4 Correct 335 ms 767752 KB Output is correct
5 Correct 337 ms 767872 KB Output is correct
6 Correct 335 ms 767820 KB Output is correct
7 Correct 338 ms 764080 KB Output is correct
8 Correct 336 ms 764088 KB Output is correct
9 Correct 331 ms 760148 KB Output is correct
10 Correct 346 ms 767856 KB Output is correct
11 Correct 348 ms 767796 KB Output is correct
12 Correct 102 ms 205376 KB Output is correct
13 Correct 159 ms 361868 KB Output is correct
14 Correct 228 ms 523632 KB Output is correct
15 Correct 362 ms 767876 KB Output is correct
16 Correct 341 ms 767852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 852 KB Output is correct
5 Correct 1 ms 1620 KB Output is correct
6 Correct 1 ms 1620 KB Output is correct
7 Correct 1 ms 1620 KB Output is correct
8 Correct 1 ms 1620 KB Output is correct
9 Correct 1 ms 1528 KB Output is correct
10 Correct 1 ms 1620 KB Output is correct
11 Correct 1 ms 1620 KB Output is correct
12 Correct 1 ms 1620 KB Output is correct
13 Correct 1 ms 1620 KB Output is correct
14 Correct 1 ms 1364 KB Output is correct
15 Correct 1 ms 1620 KB Output is correct
16 Correct 1 ms 1620 KB Output is correct
17 Correct 1 ms 1364 KB Output is correct
18 Correct 8 ms 18388 KB Output is correct
19 Correct 8 ms 18388 KB Output is correct
20 Correct 10 ms 18516 KB Output is correct
21 Correct 8 ms 18388 KB Output is correct
22 Correct 8 ms 18388 KB Output is correct
23 Correct 8 ms 18360 KB Output is correct
24 Correct 8 ms 18388 KB Output is correct
25 Correct 8 ms 18348 KB Output is correct
26 Correct 7 ms 18388 KB Output is correct
27 Correct 9 ms 18388 KB Output is correct
28 Correct 8 ms 18292 KB Output is correct
29 Correct 8 ms 18388 KB Output is correct
30 Correct 9 ms 18400 KB Output is correct
31 Correct 9 ms 18456 KB Output is correct
32 Correct 9 ms 18360 KB Output is correct
33 Correct 8 ms 17748 KB Output is correct
34 Correct 8 ms 17748 KB Output is correct
35 Correct 8 ms 17236 KB Output is correct
36 Correct 8 ms 17748 KB Output is correct
37 Correct 8 ms 16596 KB Output is correct
38 Correct 9 ms 18388 KB Output is correct
39 Correct 8 ms 18388 KB Output is correct
40 Correct 8 ms 17748 KB Output is correct
41 Correct 8 ms 18388 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 375 ms 767876 KB Output is correct
44 Correct 340 ms 764056 KB Output is correct
45 Correct 335 ms 767752 KB Output is correct
46 Correct 337 ms 767872 KB Output is correct
47 Correct 335 ms 767820 KB Output is correct
48 Correct 338 ms 764080 KB Output is correct
49 Correct 336 ms 764088 KB Output is correct
50 Correct 331 ms 760148 KB Output is correct
51 Correct 346 ms 767856 KB Output is correct
52 Correct 348 ms 767796 KB Output is correct
53 Correct 102 ms 205376 KB Output is correct
54 Correct 159 ms 361868 KB Output is correct
55 Correct 228 ms 523632 KB Output is correct
56 Correct 362 ms 767876 KB Output is correct
57 Correct 341 ms 767852 KB Output is correct
58 Correct 430 ms 767972 KB Output is correct
59 Correct 430 ms 767872 KB Output is correct
60 Correct 425 ms 760248 KB Output is correct
61 Correct 421 ms 764024 KB Output is correct
62 Correct 356 ms 767924 KB Output is correct
63 Correct 372 ms 767828 KB Output is correct
64 Correct 390 ms 767800 KB Output is correct
65 Correct 398 ms 764120 KB Output is correct
66 Correct 424 ms 756488 KB Output is correct
67 Correct 425 ms 767868 KB Output is correct
68 Correct 433 ms 763980 KB Output is correct
69 Correct 424 ms 767824 KB Output is correct
70 Correct 424 ms 767820 KB Output is correct
71 Correct 429 ms 764052 KB Output is correct
72 Correct 376 ms 764000 KB Output is correct
73 Correct 343 ms 767800 KB Output is correct