Submission #265422

# Submission time Handle Problem Language Result Execution time Memory
265422 2020-08-14T20:01:58 Z MKopchev Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
15 / 100
71 ms 97272 KB
#include<bits/stdc++.h>
using namespace std;
const int nmax=400+5,inf=1e9;

int n;
int inp[nmax];

int where[3][nmax],pointer[3];

int dp[3][nmax/2][nmax/2][nmax/2];

int rec(int prv,int cnt_0,int cnt_1,int cnt_2)
{
    //cout<<prv<<" "<<cnt_0<<" "<<cnt_1<<" "<<cnt_2<<endl;

    if(cnt_0==pointer[0]&&cnt_1==pointer[1]&&cnt_2==pointer[2])return 0;

    if(prv!=-1&&dp[prv][cnt_0][cnt_1][cnt_2]!=-1)return dp[prv][cnt_0][cnt_1][cnt_2];

    int seen[3]={cnt_0,cnt_1,cnt_2};

    int ret=inf;

    for(int cur=0;cur<3;cur++)
        if(cur!=prv&&seen[cur]<pointer[cur])
        {
            int would=where[cur][seen[cur]+1],should=cnt_0+cnt_1+cnt_2+1;

            ret=min(ret,abs(would-should)+rec(cur,cnt_0+(cur==0),cnt_1+(cur==1),cnt_2+(cur==2)));
        }

    if(prv!=-1)dp[prv][cnt_0][cnt_1][cnt_2]=ret;
    return ret;
}
int main()
{
    memset(dp,-1,sizeof(dp));
    scanf("%i",&n);
    for(int i=1;i<=n;i++)
    {
        char c=getchar();
        while(c!='R'&&c!='G'&&c!='Y')c=getchar();

        if(c=='R')inp[i]=0;
        if(c=='G')inp[i]=1;
        if(c=='Y')inp[i]=2;

        pointer[inp[i]]++;
        where[inp[i]][pointer[inp[i]]]=i;
    }

    int MX=(n+1)/2;
    if(pointer[0]>MX||pointer[1]>MX||pointer[2]>MX)
    {
        printf("-1\n");
        return 0;
    }

    if(rec(-1,0,0,0)>=inf)printf("-1\n");
    else
    {
        printf("%i\n",rec(-1,0,0,0)/2);
        assert(rec(-1,0,0,0)%2==0);
    }
    return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |     scanf("%i",&n);
      |     ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 56 ms 97144 KB Output is correct
2 Correct 57 ms 97116 KB Output is correct
3 Correct 56 ms 97144 KB Output is correct
4 Correct 63 ms 97144 KB Output is correct
5 Correct 57 ms 97144 KB Output is correct
6 Correct 61 ms 97084 KB Output is correct
7 Correct 62 ms 97144 KB Output is correct
8 Correct 60 ms 97144 KB Output is correct
9 Correct 56 ms 97144 KB Output is correct
10 Correct 62 ms 97144 KB Output is correct
11 Incorrect 57 ms 97148 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 97144 KB Output is correct
2 Correct 57 ms 97116 KB Output is correct
3 Correct 56 ms 97144 KB Output is correct
4 Correct 63 ms 97144 KB Output is correct
5 Correct 57 ms 97144 KB Output is correct
6 Correct 61 ms 97084 KB Output is correct
7 Correct 62 ms 97144 KB Output is correct
8 Correct 60 ms 97144 KB Output is correct
9 Correct 56 ms 97144 KB Output is correct
10 Correct 62 ms 97144 KB Output is correct
11 Incorrect 57 ms 97148 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 97088 KB Output is correct
2 Correct 60 ms 97120 KB Output is correct
3 Correct 59 ms 97144 KB Output is correct
4 Correct 62 ms 97148 KB Output is correct
5 Correct 58 ms 97144 KB Output is correct
6 Correct 62 ms 97144 KB Output is correct
7 Correct 58 ms 97272 KB Output is correct
8 Correct 56 ms 97144 KB Output is correct
9 Correct 56 ms 97144 KB Output is correct
10 Correct 71 ms 97144 KB Output is correct
11 Correct 58 ms 97144 KB Output is correct
12 Correct 56 ms 97144 KB Output is correct
13 Correct 56 ms 97144 KB Output is correct
14 Correct 56 ms 97084 KB Output is correct
15 Correct 57 ms 97144 KB Output is correct
16 Correct 57 ms 97144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 97144 KB Output is correct
2 Correct 57 ms 97116 KB Output is correct
3 Correct 56 ms 97144 KB Output is correct
4 Correct 63 ms 97144 KB Output is correct
5 Correct 57 ms 97144 KB Output is correct
6 Correct 61 ms 97084 KB Output is correct
7 Correct 62 ms 97144 KB Output is correct
8 Correct 60 ms 97144 KB Output is correct
9 Correct 56 ms 97144 KB Output is correct
10 Correct 62 ms 97144 KB Output is correct
11 Incorrect 57 ms 97148 KB Output isn't correct
12 Halted 0 ms 0 KB -