답안 #234490

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
234490 2020-05-24T10:07:53 Z nicolaalexandra Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
103 ms 163064 KB
#include <bits/stdc++.h>
#define DIM 402
#define INF 2000000000
using namespace std;
int dp[DIM][DIM][DIM][3],cnt[3][DIM];
vector <int> poz[3];
char v[DIM];
int n,i,j,k;
int main (){

    //ifstream cin ("date.in");
    //ofstream cout ("date.out");

    cin>>n>>v+1;
    for (i=1;i<=n;i++){
        cnt[0][i] = cnt[0][i-1];
        cnt[1][i] = cnt[1][i-1];
        cnt[2][i] = cnt[2][i-1];

        if (v[i] == 'R'){
            poz[0].push_back(i);
            cnt[0][i]++;
        } else {
            if (v[i] == 'G'){
                poz[1].push_back(i);
                cnt[1][i]++;
            } else {
                poz[2].push_back(i);
                cnt[2][i]++;
            }
        }
    }

    /// dp[nr0][nr1][nr2][0/1/2]

    for (i=0;i<=poz[0].size();i++)
        for (j=0;j<=poz[1].size();j++)
            for (k=0;k<=poz[2].size();k++)
                dp[i][j][k][0] = dp[i][j][k][1] = dp[i][j][k][2] = INF;

    dp[0][0][0][0] = dp[0][0][0][1] = dp[0][0][0][2] = 0;

    int a = poz[0].size(), b = poz[1].size(), c = poz[2].size();

    for (i=1;i<=n;i++)
        for (int nr0=0;nr0<=min(i,a);nr0++)
            for (int nr1=0;nr1<=min(i,b) && nr0 + nr1 <= i;nr1++){
                int nr2 = i - nr0 - nr1;
                if (nr2 > c)
                    continue;

                /// incerc sa pun un 0
                if (nr0){
                    int pos = poz[0][nr0-1];
                    int val = max (cnt[1][pos] - nr1,0) + max (cnt[2][pos] - nr2,0);

                    if (dp[nr0-1][nr1][nr2][1] != INF)
                        dp[nr0][nr1][nr2][0] = min (dp[nr0][nr1][nr2][0], dp[nr0-1][nr1][nr2][1] + val);
                    if (dp[nr0-1][nr1][nr2][2] != INF)
                        dp[nr0][nr1][nr2][0] = min (dp[nr0][nr1][nr2][0], dp[nr0-1][nr1][nr2][2] + val);
                }

                /// incerc sa pun 1
                if (nr1){
                    int pos = poz[1][nr1-1];
                    int val = max (cnt[0][pos] - nr0,0) + max (cnt[2][pos] - nr2, 0);

                    if (dp[nr0][nr1-1][nr2][0] != INF)
                        dp[nr0][nr1][nr2][1] = min (dp[nr0][nr1][nr2][1], dp[nr0][nr1-1][nr2][0] + val);
                    if (dp[nr0][nr1-1][nr2][2] != INF)
                        dp[nr0][nr1][nr2][1] = min (dp[nr0][nr1][nr2][1], dp[nr0][nr1-1][nr2][2] + val);
                }


                /// incerec sa pun 2
                if (nr2){
                    int pos = poz[2][nr2-1];
                    int val = max (cnt[0][pos] - nr0,0) + max (cnt[1][pos] - nr1, 0);

                    if (dp[nr0][nr1][nr2-1][0] != INF)
                        dp[nr0][nr1][nr2][2] = min (dp[nr0][nr1][nr2][2], dp[nr0][nr1][nr2-1][0] + val);
                    if (dp[nr0][nr1][nr2-1][1] != INF)
                        dp[nr0][nr1][nr2][2] = min (dp[nr0][nr1][nr2][2], dp[nr0][nr1][nr2-1][1] + val);
                }
            }

    int sol = INF;
    sol = min (sol, dp[a][b][c][0]);
    sol = min (sol, dp[a][b][c][1]);
    sol = min (sol, dp[a][b][c][2]);

    if (sol == INF)
        cout<<-1;
    else cout<<sol;

    return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:14:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     cin>>n>>v+1;
             ~^~
joi2019_ho_t3.cpp:36:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<=poz[0].size();i++)
              ~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:37:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j=0;j<=poz[1].size();j++)
                  ~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:38:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (k=0;k<=poz[2].size();k++)
                      ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 4 ms 512 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 5 ms 640 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 4 ms 512 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 5 ms 640 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 2304 KB Output is correct
19 Correct 6 ms 1920 KB Output is correct
20 Correct 5 ms 2304 KB Output is correct
21 Correct 6 ms 2432 KB Output is correct
22 Correct 5 ms 1792 KB Output is correct
23 Correct 5 ms 2176 KB Output is correct
24 Correct 5 ms 1664 KB Output is correct
25 Correct 6 ms 3968 KB Output is correct
26 Correct 6 ms 4224 KB Output is correct
27 Correct 6 ms 3072 KB Output is correct
28 Correct 5 ms 2304 KB Output is correct
29 Correct 5 ms 2304 KB Output is correct
30 Correct 5 ms 2304 KB Output is correct
31 Correct 5 ms 2048 KB Output is correct
32 Correct 6 ms 2432 KB Output is correct
33 Correct 6 ms 3840 KB Output is correct
34 Correct 6 ms 3584 KB Output is correct
35 Correct 6 ms 2688 KB Output is correct
36 Correct 5 ms 1920 KB Output is correct
37 Correct 5 ms 1792 KB Output is correct
38 Correct 5 ms 2176 KB Output is correct
39 Correct 5 ms 2304 KB Output is correct
40 Correct 5 ms 512 KB Output is correct
41 Correct 5 ms 2176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 94 ms 163000 KB Output is correct
3 Correct 88 ms 162168 KB Output is correct
4 Correct 87 ms 162936 KB Output is correct
5 Correct 91 ms 163064 KB Output is correct
6 Correct 88 ms 163064 KB Output is correct
7 Correct 92 ms 162324 KB Output is correct
8 Correct 91 ms 162168 KB Output is correct
9 Correct 87 ms 161400 KB Output is correct
10 Correct 88 ms 162936 KB Output is correct
11 Correct 89 ms 162936 KB Output is correct
12 Correct 26 ms 44032 KB Output is correct
13 Correct 46 ms 77184 KB Output is correct
14 Correct 62 ms 111352 KB Output is correct
15 Correct 92 ms 162940 KB Output is correct
16 Correct 91 ms 162936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 4 ms 512 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 5 ms 640 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 2304 KB Output is correct
19 Correct 6 ms 1920 KB Output is correct
20 Correct 5 ms 2304 KB Output is correct
21 Correct 6 ms 2432 KB Output is correct
22 Correct 5 ms 1792 KB Output is correct
23 Correct 5 ms 2176 KB Output is correct
24 Correct 5 ms 1664 KB Output is correct
25 Correct 6 ms 3968 KB Output is correct
26 Correct 6 ms 4224 KB Output is correct
27 Correct 6 ms 3072 KB Output is correct
28 Correct 5 ms 2304 KB Output is correct
29 Correct 5 ms 2304 KB Output is correct
30 Correct 5 ms 2304 KB Output is correct
31 Correct 5 ms 2048 KB Output is correct
32 Correct 6 ms 2432 KB Output is correct
33 Correct 6 ms 3840 KB Output is correct
34 Correct 6 ms 3584 KB Output is correct
35 Correct 6 ms 2688 KB Output is correct
36 Correct 5 ms 1920 KB Output is correct
37 Correct 5 ms 1792 KB Output is correct
38 Correct 5 ms 2176 KB Output is correct
39 Correct 5 ms 2304 KB Output is correct
40 Correct 5 ms 512 KB Output is correct
41 Correct 5 ms 2176 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 94 ms 163000 KB Output is correct
44 Correct 88 ms 162168 KB Output is correct
45 Correct 87 ms 162936 KB Output is correct
46 Correct 91 ms 163064 KB Output is correct
47 Correct 88 ms 163064 KB Output is correct
48 Correct 92 ms 162324 KB Output is correct
49 Correct 91 ms 162168 KB Output is correct
50 Correct 87 ms 161400 KB Output is correct
51 Correct 88 ms 162936 KB Output is correct
52 Correct 89 ms 162936 KB Output is correct
53 Correct 26 ms 44032 KB Output is correct
54 Correct 46 ms 77184 KB Output is correct
55 Correct 62 ms 111352 KB Output is correct
56 Correct 92 ms 162940 KB Output is correct
57 Correct 91 ms 162936 KB Output is correct
58 Correct 97 ms 75768 KB Output is correct
59 Correct 98 ms 95992 KB Output is correct
60 Correct 93 ms 87164 KB Output is correct
61 Correct 88 ms 84216 KB Output is correct
62 Correct 89 ms 160632 KB Output is correct
63 Correct 97 ms 160248 KB Output is correct
64 Correct 103 ms 150136 KB Output is correct
65 Correct 102 ms 138488 KB Output is correct
66 Correct 90 ms 85624 KB Output is correct
67 Correct 88 ms 82304 KB Output is correct
68 Correct 92 ms 88064 KB Output is correct
69 Correct 91 ms 84856 KB Output is correct
70 Correct 95 ms 91896 KB Output is correct
71 Correct 97 ms 83448 KB Output is correct
72 Correct 35 ms 41344 KB Output is correct
73 Correct 7 ms 2816 KB Output is correct