답안 #915317

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
915317 2024-01-23T16:35:48 Z ace5 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
100 / 100
311 ms 31068 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 400;


const int INF = 1e9;

vector<int> pos[3];
vector<vector<vector<int>>> dp[3];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    for(int j = 0;j < n;++j)
    {
        if(s[j] == 'R')
        {
            pos[0].push_back(j);
        }
        else if(s[j] == 'G')
        {
            pos[1].push_back(j);
        }
        else
            pos[2].push_back(j);
    }
    for(int i = 0;i < 3;++i)
    {
        dp[i].resize(pos[0].size()+1);
        for(int j=  0;j < dp[i].size();++j)
        {
            dp[i][j].resize(pos[1].size()+1);
            for(int k = 0;k < dp[i][j].size();++k)
            {
                dp[i][j][k].resize(pos[2].size()+1);
            }
        }
    }
    int k[3] = {0};
    for(k[0] = 0;k[0] <= pos[0].size();++k[0])
    {
        for(k[1] = 0;k[1] <= pos[1].size();++k[1])
        {
            for(k[2] = 0;k[2] <= pos[2].size();++k[2])
            {
                for(int last = 0;last < 3;++last)
                {
                    auto &cdp = dp[last][k[0]][k[1]][k[2]];
                    if(k[0]+k[1]+k[2] == 0)
                    {
                        cdp = 0;
                        continue;
                    }
                    cdp = INF;
                    if(k[last] != 0)
                    {
                        int cpos = pos[last][k[last]-1];
                        int ind0 = upper_bound(pos[0].begin(),pos[0].end(),cpos)-pos[0].begin();
                        int ind1 = upper_bound(pos[1].begin(),pos[1].end(),cpos)-pos[1].begin();
                        int ind2 = upper_bound(pos[2].begin(),pos[2].end(),cpos)-pos[2].begin();
                        int c = max(0,k[0]-ind0) + max(0,k[1]-ind1) + max(0,k[2]-ind2);
                        k[last]--;
                        for(int nlast = 0;nlast < 3;++nlast)
                        {
                            if(nlast != last)
                            {
                                cdp = min(cdp,c + dp[nlast][k[0]][k[1]][k[2]]);
                            }
                        }
                        k[last]++;
                    }
                }
            }
        }
    }
    int ans = INF;
    for(int le = 0;le < 3;++le)
       ans = min(ans,dp[le][pos[0].size()][pos[1].size()][pos[2].size()]);
    cout << (ans == INF ? -1 : ans);
    return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:37:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::vector<int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for(int j=  0;j < dp[i].size();++j)
      |                       ~~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:40:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |             for(int k = 0;k < dp[i][j].size();++k)
      |                           ~~^~~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(k[0] = 0;k[0] <= pos[0].size();++k[0])
      |                  ~~~~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:49:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for(k[1] = 0;k[1] <= pos[1].size();++k[1])
      |                      ~~~~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:51:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |             for(k[2] = 0;k[2] <= pos[2].size();++k[2])
      |                          ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 456 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 2 ms 600 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 532 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 600 KB Output is correct
39 Correct 2 ms 600 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 10 ms 6872 KB Output is correct
3 Correct 10 ms 7004 KB Output is correct
4 Correct 10 ms 7004 KB Output is correct
5 Correct 10 ms 6960 KB Output is correct
6 Correct 10 ms 7000 KB Output is correct
7 Correct 11 ms 7004 KB Output is correct
8 Correct 13 ms 7056 KB Output is correct
9 Correct 11 ms 7004 KB Output is correct
10 Correct 11 ms 7004 KB Output is correct
11 Correct 11 ms 7004 KB Output is correct
12 Correct 3 ms 2140 KB Output is correct
13 Correct 5 ms 3420 KB Output is correct
14 Correct 7 ms 4956 KB Output is correct
15 Correct 11 ms 7124 KB Output is correct
16 Correct 10 ms 7004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 456 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 2 ms 600 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 532 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 600 KB Output is correct
39 Correct 2 ms 600 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 10 ms 6872 KB Output is correct
44 Correct 10 ms 7004 KB Output is correct
45 Correct 10 ms 7004 KB Output is correct
46 Correct 10 ms 6960 KB Output is correct
47 Correct 10 ms 7000 KB Output is correct
48 Correct 11 ms 7004 KB Output is correct
49 Correct 13 ms 7056 KB Output is correct
50 Correct 11 ms 7004 KB Output is correct
51 Correct 11 ms 7004 KB Output is correct
52 Correct 11 ms 7004 KB Output is correct
53 Correct 3 ms 2140 KB Output is correct
54 Correct 5 ms 3420 KB Output is correct
55 Correct 7 ms 4956 KB Output is correct
56 Correct 11 ms 7124 KB Output is correct
57 Correct 10 ms 7004 KB Output is correct
58 Correct 311 ms 30808 KB Output is correct
59 Correct 311 ms 31068 KB Output is correct
60 Correct 310 ms 30112 KB Output is correct
61 Correct 309 ms 30776 KB Output is correct
62 Correct 27 ms 6748 KB Output is correct
63 Correct 45 ms 8540 KB Output is correct
64 Correct 152 ms 18736 KB Output is correct
65 Correct 221 ms 23064 KB Output is correct
66 Correct 249 ms 30296 KB Output is correct
67 Correct 254 ms 30292 KB Output is correct
68 Correct 267 ms 30416 KB Output is correct
69 Correct 275 ms 30984 KB Output is correct
70 Correct 275 ms 30840 KB Output is correct
71 Correct 289 ms 30420 KB Output is correct
72 Correct 86 ms 8788 KB Output is correct
73 Correct 17 ms 2392 KB Output is correct