Submission #670500

# Submission time Handle Problem Language Result Execution time Memory
670500 2022-12-09T10:43:21 Z berr Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
60 / 100
500 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;    
#define int long long
int a[405][3][405][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++){
        if(s[i-1]=='R') b[0].push_back(i);
        if(s[i-1]=='Y') b[1].push_back(i);
        if(s[i-1]=='G') b[2].push_back(i);
    }


    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]=1e18;
                }
            }
        }
    }


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

    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(0LL, lower_bound(b[0].begin(), b[0].end(), b[t][f])-b[0].begin()-l-1);
                    dist+=max(0LL, lower_bound(b[1].begin(), b[1].end(), b[t][f])-b[1].begin()-j-1);
                    dist+=max(0LL, lower_bound(b[2].begin(), b[2].end(), b[t][f])-b[2].begin()-k-1);

                    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(0LL, 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(0LL, 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>=1e18) cout<<-1;
    else cout<<ans;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:42:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for(int l=0; l<=i&&l<b[0].size()-1; l++){
      |                            ~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:43:35: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |             for(int j=0; j+l<=i&&j<b[1].size()-1; j++){
      |                                  ~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:45:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |                 if(k<b[2].size()-1)
      |                    ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 1488 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2764 KB Output is correct
7 Correct 1 ms 2772 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 1 ms 2772 KB Output is correct
10 Correct 1 ms 2772 KB Output is correct
11 Correct 1 ms 2772 KB Output is correct
12 Correct 1 ms 2772 KB Output is correct
13 Correct 1 ms 2760 KB Output is correct
14 Correct 1 ms 2376 KB Output is correct
15 Correct 1 ms 2772 KB Output is correct
16 Correct 1 ms 2772 KB Output is correct
17 Correct 1 ms 2388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 1488 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2764 KB Output is correct
7 Correct 1 ms 2772 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 1 ms 2772 KB Output is correct
10 Correct 1 ms 2772 KB Output is correct
11 Correct 1 ms 2772 KB Output is correct
12 Correct 1 ms 2772 KB Output is correct
13 Correct 1 ms 2760 KB Output is correct
14 Correct 1 ms 2376 KB Output is correct
15 Correct 1 ms 2772 KB Output is correct
16 Correct 1 ms 2772 KB Output is correct
17 Correct 1 ms 2388 KB Output is correct
18 Correct 15 ms 35744 KB Output is correct
19 Correct 15 ms 35660 KB Output is correct
20 Correct 16 ms 35668 KB Output is correct
21 Correct 16 ms 35668 KB Output is correct
22 Correct 15 ms 35668 KB Output is correct
23 Correct 15 ms 35668 KB Output is correct
24 Correct 15 ms 35696 KB Output is correct
25 Correct 18 ms 35672 KB Output is correct
26 Correct 14 ms 35660 KB Output is correct
27 Correct 18 ms 35668 KB Output is correct
28 Correct 17 ms 35644 KB Output is correct
29 Correct 15 ms 35692 KB Output is correct
30 Correct 16 ms 35668 KB Output is correct
31 Correct 16 ms 35668 KB Output is correct
32 Correct 15 ms 35664 KB Output is correct
33 Correct 15 ms 34620 KB Output is correct
34 Correct 14 ms 34516 KB Output is correct
35 Correct 15 ms 33364 KB Output is correct
36 Correct 17 ms 34576 KB Output is correct
37 Correct 14 ms 32372 KB Output is correct
38 Correct 15 ms 35668 KB Output is correct
39 Correct 16 ms 35668 KB Output is correct
40 Correct 14 ms 34640 KB Output is correct
41 Correct 14 ms 35668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Execution timed out 571 ms 1048576 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 1488 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2764 KB Output is correct
7 Correct 1 ms 2772 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 1 ms 2772 KB Output is correct
10 Correct 1 ms 2772 KB Output is correct
11 Correct 1 ms 2772 KB Output is correct
12 Correct 1 ms 2772 KB Output is correct
13 Correct 1 ms 2760 KB Output is correct
14 Correct 1 ms 2376 KB Output is correct
15 Correct 1 ms 2772 KB Output is correct
16 Correct 1 ms 2772 KB Output is correct
17 Correct 1 ms 2388 KB Output is correct
18 Correct 15 ms 35744 KB Output is correct
19 Correct 15 ms 35660 KB Output is correct
20 Correct 16 ms 35668 KB Output is correct
21 Correct 16 ms 35668 KB Output is correct
22 Correct 15 ms 35668 KB Output is correct
23 Correct 15 ms 35668 KB Output is correct
24 Correct 15 ms 35696 KB Output is correct
25 Correct 18 ms 35672 KB Output is correct
26 Correct 14 ms 35660 KB Output is correct
27 Correct 18 ms 35668 KB Output is correct
28 Correct 17 ms 35644 KB Output is correct
29 Correct 15 ms 35692 KB Output is correct
30 Correct 16 ms 35668 KB Output is correct
31 Correct 16 ms 35668 KB Output is correct
32 Correct 15 ms 35664 KB Output is correct
33 Correct 15 ms 34620 KB Output is correct
34 Correct 14 ms 34516 KB Output is correct
35 Correct 15 ms 33364 KB Output is correct
36 Correct 17 ms 34576 KB Output is correct
37 Correct 14 ms 32372 KB Output is correct
38 Correct 15 ms 35668 KB Output is correct
39 Correct 16 ms 35668 KB Output is correct
40 Correct 14 ms 34640 KB Output is correct
41 Correct 14 ms 35668 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Execution timed out 571 ms 1048576 KB Time limit exceeded
44 Halted 0 ms 0 KB -