Submission #156505

# Submission time Handle Problem Language Result Execution time Memory
156505 2019-10-06T09:03:56 Z vex Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
15 / 100
133 ms 163100 KB
///10:32
///10:55
///
#include<bits/stdc++.h>
#define INF 100000000
#define maxn 405
using namespace std;

map<char,int>br;
int n;
string s;
int dp[maxn][maxn][maxn][3];
int col[maxn][3];
int tot[3];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    br['R']=0;
    br['G']=1;
    br['Y']=2;

    cin>>n;
    cin>>s;

    tot[0]=tot[1]=tot[2]=0;
    for(int i=0;i<n;i++)
    {
        int boja=br[s[i]];
        //cout<<boja<<" ";
        tot[boja]++;
        col[tot[boja]][boja]=i;
    }
    /*cout<<endl;

    for(int i=0;i<=2;i++)
    {
        cout<<tot[i]<<"  ";
        for(int j=1;j<=tot[i];j++)
        {
            cout<<col[j][i]<<" ";
        }
        cout<<endl;
    }*/



    int red[3];
    for(red[0]=0;red[0]<=tot[0];red[0]++)
    {
        for(red[1]=0;red[1]<=tot[1];red[1]++)
        {
            for(red[2]=0;red[2]<=tot[2];red[2]++)
            {
                for(int i=0;i<=2;i++)
                {
                    dp[ red[0] ][ red[1] ][ red[2] ][i]=INF;
                    if(red[i]==0)continue;

                    int poz=red[0]+red[1]+red[2]-1;
                    int dod=abs(col[red[i]][i]-poz);
                    int ost1=(i+1)%3;
                    int ost2=(i+2)%3;
                    if(poz==0)
                    {
                        dp[ red[0] ][ red[1] ][ red[2] ][i]=dod;
                        continue;
                    }

                    int tre[3];
                    for(int j=0;j<=2;j++)
                    {
                        tre[j]=red[j];
                    }
                    tre[i]--;


                    dp[ red[0] ][ red[1] ][ red[2] ][i]=min(dp[ red[0] ][ red[1] ][ red[2] ][i], dp[ tre[0] ][ tre[1] ][ tre[2] ][ost1] + dod);
                    dp[ red[0] ][ red[1] ][ red[2] ][i]=min(dp[ red[0] ][ red[1] ][ red[2] ][i], dp[ tre[0] ][ tre[1] ][ tre[2] ][ost2] + dod);
                }
            }
        }
    }

    int sol=INF;
    for(int i=0;i<=2;i++)
    {
        sol=min(sol,dp[ tot[0] ][ tot[1] ][ tot[2] ][i]);
    }

    if(sol==INF)cout<<"-1"<<endl;
    else
    {
        sol/=2;
        cout<<sol<<endl;
    }

    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Incorrect 2 ms 632 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Incorrect 2 ms 632 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 122 ms 163020 KB Output is correct
3 Correct 122 ms 162208 KB Output is correct
4 Correct 122 ms 163036 KB Output is correct
5 Correct 123 ms 163064 KB Output is correct
6 Correct 133 ms 163100 KB Output is correct
7 Correct 122 ms 162184 KB Output is correct
8 Correct 122 ms 162252 KB Output is correct
9 Correct 123 ms 161360 KB Output is correct
10 Correct 124 ms 163080 KB Output is correct
11 Correct 123 ms 162936 KB Output is correct
12 Correct 36 ms 44024 KB Output is correct
13 Correct 60 ms 77176 KB Output is correct
14 Correct 86 ms 111488 KB Output is correct
15 Correct 122 ms 162936 KB Output is correct
16 Correct 124 ms 162936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Incorrect 2 ms 632 KB Output isn't correct
12 Halted 0 ms 0 KB -