Submission #936956

# Submission time Handle Problem Language Result Execution time Memory
936956 2024-03-03T06:04:57 Z Maite_Morale Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
75 / 100
311 ms 197408 KB
    #include<bits/stdc++.h>
    #define F first
    #define S second
    #define MAX 405
    #define oo 1e18
    #define mod 1000000007
    #define fast_in ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.setf(ios::fixed);cout.precision(0);
    using namespace std;
    typedef long long ll;
    #define pll pair<ll , ll>
    #define vll vector<ll>
    #define vvll vector<vll>
    #define vpll vector<pll>
     
    ll n,t[5][405];
    vll v[5];
    string a;
    ll dp[400][400][50][10],s[10]={0,0,0};
    ll cost(vll x,ll z){
        ll r=0;ll p=v[z][x[z]-1]-1;
        for(int i=0;i<3;i++){
            if(i==z)continue;
            r+=max(0LL,t[i][p]-x[i]);
        }
    return r;
    }
    int main(){
        fast_in
        cin>>n>>a;
        for(int i=0;i<n;i++){
            if(a[i]=='R'){v[0].push_back(i+1);t[0][i]++;}
            if(a[i]=='G'){v[1].push_back(i+1);t[1][i]++;}
            if(a[i]=='Y'){v[2].push_back(i+1);t[2][i]++;}
            if(i==0)continue;
            t[0][i]+=t[0][i-1];
            t[1][i]+=t[1][i-1];
            t[2][i]+=t[2][i-1];
        }
        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++){
                    for(int h=0;h<3;h++){
                        if(i+j+k==0){
                            dp[i][j][k][h]=0;
                          //  cout<<i<<" "<<j<<" "<<k<<" "<<h<<" "<<dp[i][j][k][h]<<".\n";
                            continue;
                        }
                        s[h]=1;dp[i][j][k][h]=oo;
                        if(min(i-s[0],min(j-s[1],k-s[2]))<0){
                            s[h]=0;
                           // cout<<i<<" "<<j<<" "<<k<<" "<<h<<" "<<dp[i][j][k][h]<<"_\n";
                            continue;
                        }
                        for(int h1=0;h1<3;h1++){
                            if(h1==h)continue;
                            ll z=dp[i][j][k][h],w=dp[i-s[0]][j-s[1]][k-s[2]][h1],w1=cost({i,j,k},h);
                            dp[i][j][k][h]=min(z,w+w1);
                        }
                       // cout<<i<<" "<<j<<" "<<k<<" "<<h<<" "<<dp[i][j][k][h]<<"\n";
                        s[h]=0;
                    }
                }
            }
        }
        sort(dp[v[0].size()][v[1].size()][v[2].size()],dp[v[0].size()][v[1].size()][v[2].size()]+3);
        if(dp[v[0].size()][v[1].size()][v[2].size()][0]==oo)dp[v[0].size()][v[1].size()][v[2].size()][0]=-1;
        cout<<dp[v[0].size()][v[1].size()][v[2].size()][0];
    return 0;
    }

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for(int i=0;i<=v[0].size();i++){
      |                     ~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:40:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |             for(int j=0;j<=v[1].size();j++){
      |                         ~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:41:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |                 for(int k=0;k<=v[2].size();k++){
      |                             ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 6496 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 12636 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 2 ms 16848 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 18780 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 6496 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 12636 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 2 ms 16848 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 18780 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 6 ms 37468 KB Output is correct
19 Correct 6 ms 31324 KB Output is correct
20 Correct 6 ms 41564 KB Output is correct
21 Correct 5 ms 33372 KB Output is correct
22 Correct 7 ms 39260 KB Output is correct
23 Correct 5 ms 27228 KB Output is correct
24 Correct 3 ms 16852 KB Output is correct
25 Correct 10 ms 59828 KB Output is correct
26 Correct 6 ms 49756 KB Output is correct
27 Correct 7 ms 43608 KB Output is correct
28 Correct 5 ms 33372 KB Output is correct
29 Correct 5 ms 35420 KB Output is correct
30 Correct 5 ms 27228 KB Output is correct
31 Correct 5 ms 25040 KB Output is correct
32 Correct 5 ms 29276 KB Output is correct
33 Correct 6 ms 41564 KB Output is correct
34 Correct 5 ms 35420 KB Output is correct
35 Correct 7 ms 37444 KB Output is correct
36 Correct 6 ms 33368 KB Output is correct
37 Correct 3 ms 20948 KB Output is correct
38 Correct 4 ms 23132 KB Output is correct
39 Correct 5 ms 31324 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 2 ms 14936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 54 ms 195260 KB Output is correct
3 Correct 51 ms 194640 KB Output is correct
4 Correct 51 ms 195156 KB Output is correct
5 Correct 60 ms 196368 KB Output is correct
6 Correct 51 ms 195156 KB Output is correct
7 Correct 50 ms 195412 KB Output is correct
8 Correct 51 ms 194364 KB Output is correct
9 Correct 50 ms 193876 KB Output is correct
10 Correct 50 ms 197408 KB Output is correct
11 Correct 56 ms 196352 KB Output is correct
12 Correct 18 ms 98896 KB Output is correct
13 Correct 27 ms 123228 KB Output is correct
14 Correct 36 ms 151380 KB Output is correct
15 Correct 51 ms 196096 KB Output is correct
16 Correct 50 ms 195156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 6496 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 12636 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 2 ms 16848 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 18780 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 6 ms 37468 KB Output is correct
19 Correct 6 ms 31324 KB Output is correct
20 Correct 6 ms 41564 KB Output is correct
21 Correct 5 ms 33372 KB Output is correct
22 Correct 7 ms 39260 KB Output is correct
23 Correct 5 ms 27228 KB Output is correct
24 Correct 3 ms 16852 KB Output is correct
25 Correct 10 ms 59828 KB Output is correct
26 Correct 6 ms 49756 KB Output is correct
27 Correct 7 ms 43608 KB Output is correct
28 Correct 5 ms 33372 KB Output is correct
29 Correct 5 ms 35420 KB Output is correct
30 Correct 5 ms 27228 KB Output is correct
31 Correct 5 ms 25040 KB Output is correct
32 Correct 5 ms 29276 KB Output is correct
33 Correct 6 ms 41564 KB Output is correct
34 Correct 5 ms 35420 KB Output is correct
35 Correct 7 ms 37444 KB Output is correct
36 Correct 6 ms 33368 KB Output is correct
37 Correct 3 ms 20948 KB Output is correct
38 Correct 4 ms 23132 KB Output is correct
39 Correct 5 ms 31324 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 2 ms 14936 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 54 ms 195260 KB Output is correct
44 Correct 51 ms 194640 KB Output is correct
45 Correct 51 ms 195156 KB Output is correct
46 Correct 60 ms 196368 KB Output is correct
47 Correct 51 ms 195156 KB Output is correct
48 Correct 50 ms 195412 KB Output is correct
49 Correct 51 ms 194364 KB Output is correct
50 Correct 50 ms 193876 KB Output is correct
51 Correct 50 ms 197408 KB Output is correct
52 Correct 56 ms 196352 KB Output is correct
53 Correct 18 ms 98896 KB Output is correct
54 Correct 27 ms 123228 KB Output is correct
55 Correct 36 ms 151380 KB Output is correct
56 Correct 51 ms 196096 KB Output is correct
57 Correct 50 ms 195156 KB Output is correct
58 Incorrect 311 ms 116648 KB Output isn't correct
59 Halted 0 ms 0 KB -