답안 #109481

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
109481 2019-05-06T16:55:39 Z wasyl Growing Vegetable is Fun 3 (JOI19_ho_t3) C++11
100 / 100
125 ms 50512 KB
    #pragma GCC optimize("O3")
    /*{{{*/
    #include <bits/stdc++.h>
    #ifdef LOCAL
    int c_ = 0;
    #define cout (c_?cerr:cout)
    #define debug(...) \
    {if(!c_++)cerr<<"\033[96;1m"; \
        __VA_ARGS__; \
        if(!--c_)cerr<<"\033[0m";}
    #else
    #define debug(...) {}
    #endif
    #define assrt(...) debug(\
            if (not (__VA_ARGS__)) \
            exit((cerr << __LINE__ << ": " << #__VA_ARGS__ << '\n', 0));\
            )
    #define st first
    #define nd second
    #define all(...) (__VA_ARGS__).begin(), (__VA_ARGS__).end()
    using namespace std; using ll = long long;
    template < typename t > using V = vector< t >;
    template < typename t, size_t s > using A = array< t, s >;
    void print() {cout << '\n';}
        template< typename t, typename... v >
    void print(const t& a, const v&... b)
    {cout << a << (sizeof...(b)?" ":""); print(b...);}
    template< typename t > void print_range(t a, const t& b)
    { while (a != b) cout << (*a++) << ' '; cout << '\n';}
    #define dump(...) debug(print(#__VA_ARGS__,'=',__VA_ARGS__))
    #define dump_range(...) debug(cerr<<#__VA_ARGS__ << ": "; print_range(__VA_ARGS__))
    /*}}}*/
     
    using Triple = array< int, 3 >;
    constexpr int nax = 400, ax = 200, cx = 3, inf = 1e9;
     
    int n, mem[3][ax + 1][ax + 1][ax + 1], poz[cx][ax + 1], sum[cx][nax + 1];
    string s;
     
    int& dp(const int v, const Triple& s)
    {
        return mem[v][s[0]][s[1]][s[2]];
    }
     
    void solve()
    {
        for (int i = 0; i <= sum[0][n]; ++i)
            for (int j = 0; j <= sum[1][n]; ++j)
                for (int k = 0; k <= sum[2][n]; ++k)
                    for (int l = 0; l < cx; ++l)
                    {
                        Triple s{i, j, k};
                        for (int i = 0; i < cx; ++i)
                            if (s[i] < sum[i][n] and i != l)
                            {
                                int p = poz[i][s[i] + 1];
                                int d = p;
                                for (int j = 0; j < cx; ++j)
                                    d -= min(sum[j][p], s[j] + (i == j));
                                int& a = dp(l, s);
                                ++s[i];
                                int& b = dp(i, s);
                                --s[i];
                                b = min(b, a + d);
                            }
                    }
    }
     
    int32_t main()
    {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
     
        cin >> n >> s;
     
        {
            int su[3]{};
            for (int i = 1; i <= n; ++i)
            {
                for (int j = 0; j < cx; ++j)
                    sum[j][i] = sum[j][i - 1];
                if (s[i - 1] == 'R')
                {
                    if (sum[0][i] == ax) 
                        return print(-1), 0;
                    ++sum[0][i], poz[0][sum[0][i]] = i;
                }
                if (s[i - 1] == 'Y')
                {
                    if (sum[1][i] == ax) 
                        return print(-1), 0;
                    ++sum[1][i], poz[1][sum[1][i]] = i;
                }
                if (s[i - 1] == 'G')
                {
                    if (sum[2][i] == ax) 
                        return print(-1), 0;
                    ++sum[2][i], poz[2][sum[2][i]] = i;
                }
            }
        }
     
        for (int i = 0; i <= sum[0][n]; ++i)
            for (int j = 0; j <= sum[1][n]; ++j)
                for (int k = 0; k <= sum[2][n]; ++k)
                    for (int l = 0; l < cx; ++l)
                        mem[l][i][j][k] = inf;
     
        mem[0][0][0][0] = mem[1][0][0][0] = mem[2][0][0][0] = 0;
     
        solve();
     
        int res = inf;
        for (int i = 0; i < cx; ++i)
            res = min(res, mem[i][sum[0][n]][sum[1][n]][sum[2][n]]);
     
        print((res == inf? -1 : res));
    }

Compilation message

joi2019_ho_t3.cpp: In function 'int32_t main()':
joi2019_ho_t3.cpp:77:17: warning: unused variable 'su' [-Wunused-variable]
             int su[3]{};
                 ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 2 ms 640 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 2 ms 640 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 4 ms 1708 KB Output is correct
19 Correct 4 ms 1792 KB Output is correct
20 Correct 4 ms 1920 KB Output is correct
21 Correct 3 ms 1536 KB Output is correct
22 Correct 4 ms 2176 KB Output is correct
23 Correct 4 ms 1536 KB Output is correct
24 Correct 3 ms 1152 KB Output is correct
25 Correct 3 ms 1024 KB Output is correct
26 Correct 3 ms 896 KB Output is correct
27 Correct 3 ms 1536 KB Output is correct
28 Correct 5 ms 1664 KB Output is correct
29 Correct 3 ms 1664 KB Output is correct
30 Correct 3 ms 1408 KB Output is correct
31 Correct 4 ms 1380 KB Output is correct
32 Correct 3 ms 1408 KB Output is correct
33 Correct 3 ms 768 KB Output is correct
34 Correct 3 ms 896 KB Output is correct
35 Correct 3 ms 1408 KB Output is correct
36 Correct 4 ms 1792 KB Output is correct
37 Correct 4 ms 1228 KB Output is correct
38 Correct 4 ms 1152 KB Output is correct
39 Correct 4 ms 1664 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 2 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 5 ms 3328 KB Output is correct
3 Correct 6 ms 3456 KB Output is correct
4 Correct 6 ms 3328 KB Output is correct
5 Correct 6 ms 3456 KB Output is correct
6 Correct 5 ms 3328 KB Output is correct
7 Correct 7 ms 3328 KB Output is correct
8 Correct 5 ms 3328 KB Output is correct
9 Correct 6 ms 3456 KB Output is correct
10 Correct 6 ms 3456 KB Output is correct
11 Correct 6 ms 3456 KB Output is correct
12 Correct 3 ms 1792 KB Output is correct
13 Correct 5 ms 2560 KB Output is correct
14 Correct 4 ms 2816 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 2 ms 640 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 4 ms 1708 KB Output is correct
19 Correct 4 ms 1792 KB Output is correct
20 Correct 4 ms 1920 KB Output is correct
21 Correct 3 ms 1536 KB Output is correct
22 Correct 4 ms 2176 KB Output is correct
23 Correct 4 ms 1536 KB Output is correct
24 Correct 3 ms 1152 KB Output is correct
25 Correct 3 ms 1024 KB Output is correct
26 Correct 3 ms 896 KB Output is correct
27 Correct 3 ms 1536 KB Output is correct
28 Correct 5 ms 1664 KB Output is correct
29 Correct 3 ms 1664 KB Output is correct
30 Correct 3 ms 1408 KB Output is correct
31 Correct 4 ms 1380 KB Output is correct
32 Correct 3 ms 1408 KB Output is correct
33 Correct 3 ms 768 KB Output is correct
34 Correct 3 ms 896 KB Output is correct
35 Correct 3 ms 1408 KB Output is correct
36 Correct 4 ms 1792 KB Output is correct
37 Correct 4 ms 1228 KB Output is correct
38 Correct 4 ms 1152 KB Output is correct
39 Correct 4 ms 1664 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 2 ms 640 KB Output is correct
42 Correct 3 ms 384 KB Output is correct
43 Correct 5 ms 3328 KB Output is correct
44 Correct 6 ms 3456 KB Output is correct
45 Correct 6 ms 3328 KB Output is correct
46 Correct 6 ms 3456 KB Output is correct
47 Correct 5 ms 3328 KB Output is correct
48 Correct 7 ms 3328 KB Output is correct
49 Correct 5 ms 3328 KB Output is correct
50 Correct 6 ms 3456 KB Output is correct
51 Correct 6 ms 3456 KB Output is correct
52 Correct 6 ms 3456 KB Output is correct
53 Correct 3 ms 1792 KB Output is correct
54 Correct 5 ms 2560 KB Output is correct
55 Correct 4 ms 2816 KB Output is correct
56 Correct 2 ms 384 KB Output is correct
57 Correct 2 ms 384 KB Output is correct
58 Correct 125 ms 45956 KB Output is correct
59 Correct 85 ms 42752 KB Output is correct
60 Correct 94 ms 45944 KB Output is correct
61 Correct 102 ms 44996 KB Output is correct
62 Correct 2 ms 384 KB Output is correct
63 Correct 20 ms 7096 KB Output is correct
64 Correct 55 ms 18268 KB Output is correct
65 Correct 57 ms 24312 KB Output is correct
66 Correct 89 ms 44536 KB Output is correct
67 Correct 96 ms 38144 KB Output is correct
68 Correct 108 ms 44024 KB Output is correct
69 Correct 99 ms 45984 KB Output is correct
70 Correct 91 ms 42104 KB Output is correct
71 Correct 105 ms 50512 KB Output is correct
72 Correct 3 ms 384 KB Output is correct
73 Correct 2 ms 384 KB Output is correct