Submission #539419

# Submission time Handle Problem Language Result Execution time Memory
539419 2022-03-18T20:45:33 Z Antekb Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
132 ms 41060 KB
#include<bits/stdc++.h>
using namespace std;
int ans;
string s;

int main(){
    int n;
    cin>>n;
    cin>>s;
    vector<int> V[3];
    vector<int> ile[3];
    for(int i=0; i<n; i++){
        int c=0;
        if(s[i]=='Y')c=1;
        if(s[i]=='R')c=2;
        V[c].push_back(i);
        for(int j=0; j<3; j++)ile[j].push_back(V[j].size());
    }
    vector<vector<vector<vector<int> > > > dp(3, vector<vector<vector<int> > >(V[0].size()+1
        , vector<vector<int>>(V[1].size()+1, vector<int>(V[2].size()+1, 1e9))));
    dp[0][0][0][0]=dp[1][0][0][0]=dp[2][0][0][0]=0;
    for(int s=1; s<=n; s++){
    for(int i=0; i<=V[0].size(); i++){
        for(int j=0; j<=V[1].size(); j++){
            //for(int k=0; k<=V[2].size(); k++){
                int k=s-i-j;
                if(k<0 || k>V[2].size())continue;
                //if(!k && !i && !j)continue;
                if(i)dp[0][i][j][k]=min(dp[1][i-1][j][k], dp[2][i-1][j][k])+abs(j-ile[1][V[0][i-1]])+abs(k-ile[2][V[0][i-1]]);
                if(j)dp[1][i][j][k]=min(dp[0][i][j-1][k], dp[2][i][j-1][k])+abs(i-ile[0][V[1][j-1]])+abs(k-ile[2][V[1][j-1]]);
                if(k)dp[2][i][j][k]=min(dp[1][i][j][k-1], dp[0][i][j][k-1])+abs(j-ile[1][V[2][k-1]])+abs(i-ile[0][V[2][k-1]]);
            //}
            //cout<<i<<" "<<j<<" "<<k<<" "<<dp[0][i][j][k]<<" "<<dp[1][i][j][k]<<" "<<dp[2][i][j][k]<<"\n";
        }
    }
    }
    int a=V[0].size(), b=V[1].size(), c=V[2].size();
    //cout<<a<<" "<<b<<" "<<c<<" ";
    int k=min({dp[0][a][b][c], dp[1][a][b][c], dp[2][a][b][c]});
    if(k>=1e9)cout<<-1;
    else cout<<k/2;
    //assert((k&1)==0);
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:23:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i=0; i<=V[0].size(); i++){
      |                  ~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:24:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         for(int j=0; j<=V[1].size(); j++){
      |                      ~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:27:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |                 if(k<0 || k>V[2].size())continue;
      |                           ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 428 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 432 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 432 KB Output is correct
30 Correct 1 ms 432 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 428 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 1004 KB Output is correct
3 Correct 2 ms 980 KB Output is correct
4 Correct 2 ms 940 KB Output is correct
5 Correct 2 ms 980 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 2 ms 980 KB Output is correct
9 Correct 2 ms 980 KB Output is correct
10 Correct 2 ms 980 KB Output is correct
11 Correct 2 ms 940 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 2 ms 980 KB Output is correct
16 Correct 2 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 428 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 432 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 432 KB Output is correct
30 Correct 1 ms 432 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 428 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 2 ms 1004 KB Output is correct
44 Correct 2 ms 980 KB Output is correct
45 Correct 2 ms 940 KB Output is correct
46 Correct 2 ms 980 KB Output is correct
47 Correct 2 ms 980 KB Output is correct
48 Correct 1 ms 980 KB Output is correct
49 Correct 2 ms 980 KB Output is correct
50 Correct 2 ms 980 KB Output is correct
51 Correct 2 ms 980 KB Output is correct
52 Correct 2 ms 940 KB Output is correct
53 Correct 1 ms 468 KB Output is correct
54 Correct 1 ms 596 KB Output is correct
55 Correct 2 ms 724 KB Output is correct
56 Correct 2 ms 980 KB Output is correct
57 Correct 2 ms 980 KB Output is correct
58 Correct 97 ms 41060 KB Output is correct
59 Correct 81 ms 40260 KB Output is correct
60 Correct 90 ms 40452 KB Output is correct
61 Correct 88 ms 40280 KB Output is correct
62 Correct 6 ms 3592 KB Output is correct
63 Correct 11 ms 6064 KB Output is correct
64 Correct 33 ms 19888 KB Output is correct
65 Correct 52 ms 28764 KB Output is correct
66 Correct 76 ms 39924 KB Output is correct
67 Correct 80 ms 40552 KB Output is correct
68 Correct 78 ms 40412 KB Output is correct
69 Correct 132 ms 40812 KB Output is correct
70 Correct 95 ms 40956 KB Output is correct
71 Correct 85 ms 39764 KB Output is correct
72 Correct 19 ms 10156 KB Output is correct
73 Correct 26 ms 7092 KB Output is correct