답안 #127687

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
127687 2019-07-10T00:36:47 Z arnold518 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
15 / 100
139 ms 163064 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 400;
const int INF = 200000;

int N, ans;
char S[MAXN+10];

int dp[MAXN+10][MAXN+10][MAXN+10][3];
int rcnt[MAXN+10], gcnt[MAXN+10], ycnt[MAXN+10];
vector<int> rpos, gpos, ypos;

int main()
{
    int i, j;

    scanf("%d%s", &N, S+1);
    for(i=1; i<=N; i++)
    {
        rcnt[i]=rcnt[i-1]; gcnt[i]=gcnt[i-1]; ycnt[i]=ycnt[i-1];
        if(S[i]=='R') rpos.push_back(i), rcnt[i]++;
        if(S[i]=='G') gpos.push_back(i), gcnt[i]++;
        if(S[i]=='Y') ypos.push_back(i), ycnt[i]++;
        //printf("%d %d %d\n", rcnt[i], gcnt[i], ycnt[i]);
    }


    for(int r=0; r<=rpos.size(); r++)
    {
        for(int g=0; g<=gpos.size(); g++)
        {
            for(int y=0; y<=ypos.size(); y++)
            {
                dp[r][g][y][0]=dp[r][g][y][1]=dp[r][g][y][2]=INF;
                if(r==0 && g==0 && y==0)
                {
                    dp[r][g][y][0]=dp[r][g][y][1]=dp[r][g][y][2]=0;
                    continue;
                }
                if(r!=0) dp[r][g][y][0]=min(dp[r-1][g][y][1], dp[r-1][g][y][2])+max(0, r+g+y-rpos[r-1]);
                if(g!=0) dp[r][g][y][1]=min(dp[r][g-1][y][0], dp[r][g-1][y][2])+max(0, r+g+y-gpos[g-1]);
                if(y!=0) dp[r][g][y][2]=min(dp[r][g][y-1][0], dp[r][g][y-1][1])+max(0, r+g+y-ypos[y-1]);
                //printf("%d %d %d : %d %d %d\n", r, g, y, dp[r][g][y][0], dp[r][g][y][1], dp[r][g][y][2]);
            }
        }
    }
    ans=min(min(dp[rpos.size()][gpos.size()][ypos.size()][0], dp[rpos.size()][gpos.size()][ypos.size()][1]), dp[rpos.size()][gpos.size()][ypos.size()][2]);
    if(ans>=INF) ans=-1;
    printf("%d", ans);
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:33:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int r=0; r<=rpos.size(); r++)
                  ~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:35:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int g=0; g<=gpos.size(); g++)
                      ~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:37:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int y=0; y<=ypos.size(); y++)
                          ~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:20:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
joi2019_ho_t3.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%s", &N, S+1);
     ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 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 504 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 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 504 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 123 ms 163020 KB Output is correct
3 Correct 123 ms 162252 KB Output is correct
4 Correct 123 ms 162948 KB Output is correct
5 Correct 133 ms 163040 KB Output is correct
6 Correct 124 ms 163064 KB Output is correct
7 Correct 123 ms 162168 KB Output is correct
8 Correct 123 ms 162396 KB Output is correct
9 Correct 122 ms 161400 KB Output is correct
10 Correct 124 ms 163036 KB Output is correct
11 Correct 124 ms 163020 KB Output is correct
12 Correct 35 ms 44152 KB Output is correct
13 Correct 59 ms 77176 KB Output is correct
14 Correct 85 ms 111352 KB Output is correct
15 Correct 123 ms 162980 KB Output is correct
16 Correct 139 ms 163036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 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 504 KB Output isn't correct
12 Halted 0 ms 0 KB -