답안 #161160

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
161160 2019-11-01T07:11:29 Z pr3pony Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
154 ms 4344 KB
#include<bits/stdc++.h>
using namespace std;
template<class T>
bool cmin(T & a,T b) {return b < a ? a = b, 1 : 0;}
const int N = 405;
char s[N];
int n;
int dp[2][N][N][3];
vector<int> d[3];
int pr[N][3];
int f(int i,array<int,3> a)
{
    int s = 0;
    for (int j = 0; j < 3; ++j)
        s += max(0, pr[i][j] - a[j]);
    return s - 1;
}
int main()
{
    cin >> n >> (s + 1);
    d[0] = d[1] = d[2] = {0};
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < 3; ++j) {
            pr[i][j] += pr[i-1][j];
            if ("RGY"[j] == s[i]) {
                d[j].push_back(i);
                pr[i][j]++;
            }
        }
    }
    int na=d[0].size()-1,nb=d[1].size()-1,nc=d[2].size()-1;
    memset(dp,0x3f,sizeof dp);
    memset(dp[0][0][0],0,3 * sizeof(int));
    array<int,3> a = {0,0,0}, b;
    int & i = a[0], & j = a[1], & k = a[2];
    int & x = b[0], & y = b[1], & z = b[2];
    for (int sa = 0; sa < n; ++sa) {
        memset(dp[(sa+1)%2],0x3f,sizeof dp[0]);
        for (i = 0; i <= min(na, sa); ++i) {
            for (j = 0; j <= min(nb, sa - i); ++j) {
                k = sa - i - j;
                if (k < 0 || k > nc)
                   continue; 
                b = a;
                for (int c = 0; c < 3; ++c) 
                    for (int u = 0; u < 3; ++u) 
                        if (u != c && b[u] + 1 < d[u].size()) {
                            b[u]++;
                            cmin(dp[(sa+1)%2][y][z][u], dp[sa%2][j][k][c] + f(d[u][b[u]],a));
                            b[u]--;
                        }
            }
        }
    }
    int ans = *min_element(dp[n%2][nb][nc],dp[n%2][nb][nc] + 3);
    if (ans == 0x3f3f3f3f)
        ans = -1;
    cout << ans << endl;

}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:47:48: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                         if (u != c && b[u] + 1 < d[u].size()) {
joi2019_ho_t3.cpp:36:11: warning: unused variable 'x' [-Wunused-variable]
     int & x = b[0], & y = b[1], & z = b[2];
           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4216 KB Output is correct
2 Correct 6 ms 4216 KB Output is correct
3 Correct 6 ms 4216 KB Output is correct
4 Correct 6 ms 4088 KB Output is correct
5 Correct 7 ms 4216 KB Output is correct
6 Correct 7 ms 4088 KB Output is correct
7 Correct 7 ms 4216 KB Output is correct
8 Correct 7 ms 4216 KB Output is correct
9 Correct 7 ms 4216 KB Output is correct
10 Correct 7 ms 4216 KB Output is correct
11 Correct 7 ms 4216 KB Output is correct
12 Correct 7 ms 4216 KB Output is correct
13 Correct 7 ms 4204 KB Output is correct
14 Correct 7 ms 4216 KB Output is correct
15 Correct 9 ms 4216 KB Output is correct
16 Correct 7 ms 4216 KB Output is correct
17 Correct 7 ms 4216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4216 KB Output is correct
2 Correct 6 ms 4216 KB Output is correct
3 Correct 6 ms 4216 KB Output is correct
4 Correct 6 ms 4088 KB Output is correct
5 Correct 7 ms 4216 KB Output is correct
6 Correct 7 ms 4088 KB Output is correct
7 Correct 7 ms 4216 KB Output is correct
8 Correct 7 ms 4216 KB Output is correct
9 Correct 7 ms 4216 KB Output is correct
10 Correct 7 ms 4216 KB Output is correct
11 Correct 7 ms 4216 KB Output is correct
12 Correct 7 ms 4216 KB Output is correct
13 Correct 7 ms 4204 KB Output is correct
14 Correct 7 ms 4216 KB Output is correct
15 Correct 9 ms 4216 KB Output is correct
16 Correct 7 ms 4216 KB Output is correct
17 Correct 7 ms 4216 KB Output is correct
18 Correct 11 ms 4216 KB Output is correct
19 Correct 12 ms 4216 KB Output is correct
20 Correct 12 ms 4216 KB Output is correct
21 Correct 12 ms 4216 KB Output is correct
22 Correct 12 ms 4216 KB Output is correct
23 Correct 13 ms 4216 KB Output is correct
24 Correct 11 ms 4216 KB Output is correct
25 Correct 11 ms 4216 KB Output is correct
26 Correct 12 ms 4220 KB Output is correct
27 Correct 12 ms 4264 KB Output is correct
28 Correct 12 ms 4216 KB Output is correct
29 Correct 12 ms 4216 KB Output is correct
30 Correct 12 ms 4216 KB Output is correct
31 Correct 12 ms 4216 KB Output is correct
32 Correct 12 ms 4216 KB Output is correct
33 Correct 12 ms 4216 KB Output is correct
34 Correct 12 ms 4216 KB Output is correct
35 Correct 12 ms 4216 KB Output is correct
36 Correct 12 ms 4088 KB Output is correct
37 Correct 11 ms 4216 KB Output is correct
38 Correct 12 ms 4216 KB Output is correct
39 Correct 12 ms 4216 KB Output is correct
40 Correct 12 ms 4216 KB Output is correct
41 Correct 12 ms 4220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4088 KB Output is correct
2 Correct 55 ms 4216 KB Output is correct
3 Correct 56 ms 4216 KB Output is correct
4 Correct 55 ms 4216 KB Output is correct
5 Correct 55 ms 4216 KB Output is correct
6 Correct 57 ms 4216 KB Output is correct
7 Correct 55 ms 4344 KB Output is correct
8 Correct 55 ms 4216 KB Output is correct
9 Correct 55 ms 4216 KB Output is correct
10 Correct 56 ms 4216 KB Output is correct
11 Correct 54 ms 4216 KB Output is correct
12 Correct 27 ms 4216 KB Output is correct
13 Correct 36 ms 4220 KB Output is correct
14 Correct 44 ms 4216 KB Output is correct
15 Correct 56 ms 4216 KB Output is correct
16 Correct 58 ms 4216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4216 KB Output is correct
2 Correct 6 ms 4216 KB Output is correct
3 Correct 6 ms 4216 KB Output is correct
4 Correct 6 ms 4088 KB Output is correct
5 Correct 7 ms 4216 KB Output is correct
6 Correct 7 ms 4088 KB Output is correct
7 Correct 7 ms 4216 KB Output is correct
8 Correct 7 ms 4216 KB Output is correct
9 Correct 7 ms 4216 KB Output is correct
10 Correct 7 ms 4216 KB Output is correct
11 Correct 7 ms 4216 KB Output is correct
12 Correct 7 ms 4216 KB Output is correct
13 Correct 7 ms 4204 KB Output is correct
14 Correct 7 ms 4216 KB Output is correct
15 Correct 9 ms 4216 KB Output is correct
16 Correct 7 ms 4216 KB Output is correct
17 Correct 7 ms 4216 KB Output is correct
18 Correct 11 ms 4216 KB Output is correct
19 Correct 12 ms 4216 KB Output is correct
20 Correct 12 ms 4216 KB Output is correct
21 Correct 12 ms 4216 KB Output is correct
22 Correct 12 ms 4216 KB Output is correct
23 Correct 13 ms 4216 KB Output is correct
24 Correct 11 ms 4216 KB Output is correct
25 Correct 11 ms 4216 KB Output is correct
26 Correct 12 ms 4220 KB Output is correct
27 Correct 12 ms 4264 KB Output is correct
28 Correct 12 ms 4216 KB Output is correct
29 Correct 12 ms 4216 KB Output is correct
30 Correct 12 ms 4216 KB Output is correct
31 Correct 12 ms 4216 KB Output is correct
32 Correct 12 ms 4216 KB Output is correct
33 Correct 12 ms 4216 KB Output is correct
34 Correct 12 ms 4216 KB Output is correct
35 Correct 12 ms 4216 KB Output is correct
36 Correct 12 ms 4088 KB Output is correct
37 Correct 11 ms 4216 KB Output is correct
38 Correct 12 ms 4216 KB Output is correct
39 Correct 12 ms 4216 KB Output is correct
40 Correct 12 ms 4216 KB Output is correct
41 Correct 12 ms 4220 KB Output is correct
42 Correct 6 ms 4088 KB Output is correct
43 Correct 55 ms 4216 KB Output is correct
44 Correct 56 ms 4216 KB Output is correct
45 Correct 55 ms 4216 KB Output is correct
46 Correct 55 ms 4216 KB Output is correct
47 Correct 57 ms 4216 KB Output is correct
48 Correct 55 ms 4344 KB Output is correct
49 Correct 55 ms 4216 KB Output is correct
50 Correct 55 ms 4216 KB Output is correct
51 Correct 56 ms 4216 KB Output is correct
52 Correct 54 ms 4216 KB Output is correct
53 Correct 27 ms 4216 KB Output is correct
54 Correct 36 ms 4220 KB Output is correct
55 Correct 44 ms 4216 KB Output is correct
56 Correct 56 ms 4216 KB Output is correct
57 Correct 58 ms 4216 KB Output is correct
58 Correct 152 ms 4216 KB Output is correct
59 Correct 151 ms 4216 KB Output is correct
60 Correct 153 ms 4216 KB Output is correct
61 Correct 152 ms 4316 KB Output is correct
62 Correct 62 ms 4216 KB Output is correct
63 Correct 69 ms 4220 KB Output is correct
64 Correct 99 ms 4316 KB Output is correct
65 Correct 126 ms 4216 KB Output is correct
66 Correct 149 ms 4216 KB Output is correct
67 Correct 151 ms 4216 KB Output is correct
68 Correct 154 ms 4220 KB Output is correct
69 Correct 152 ms 4216 KB Output is correct
70 Correct 153 ms 4216 KB Output is correct
71 Correct 150 ms 4344 KB Output is correct
72 Correct 73 ms 4316 KB Output is correct
73 Correct 51 ms 4220 KB Output is correct