답안 #936047

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
936047 2024-03-01T03:57:24 Z Marco_Escandon Growing Vegetable is Fun 3 (JOI19_ho_t3) C++11
100 / 100
135 ms 77984 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct st{ ll a,b,c; };
vector<st> cad[4];
ll cost(ll p1, ll p2, st asd, ll p)
{
    asd.a=max(cad[p1][p2].a,asd.a-1);
    asd.b=max(cad[p1][p2].b,asd.b-1);
    asd.c=max(cad[p1][p2].c,asd.c-1);
    return (asd.a+asd.b+asd.c-p);
}
int main()
{
    ll n;
    cin>>n;
    st asd={0,0,0};
    for(int i=0; i<4; i++)
        cad[i].push_back(asd),cad[i].push_back(asd);
    for(int i=1; i<=n; i++)
    {
        char temp;
        cin>>temp;
        if(temp=='R') asd.a++;
        if(temp=='G') asd.b++;
        if(temp=='Y') asd.c++;
        if(temp=='R') cad[1].push_back(asd);
        if(temp=='G') cad[2].push_back(asd);
        if(temp=='Y') cad[3].push_back(asd);
    }
    ll dp[4][cad[1].size()][cad[2].size()][cad[3].size()];
    
    for(int i=0; i<cad[1].size(); i++)
        for(int j=0; j<cad[2].size(); j++)
            for(int k=0; k<cad[3].size(); k++)
            dp[1][i][j][k]=dp[2][i][j][k]=dp[3][i][j][k]=1e9;
    dp[1][1][1][1]=0;
    dp[2][1][1][1]=0;
    dp[3][1][1][1]=0;
    ll sol=0;
    for(int i=1; i<cad[1].size(); i++)
    {
        for(int j=1; j<cad[2].size(); j++)
        {
            for(int k=1; k<cad[3].size(); k++)
            {
                ll asd=1e9;
                if(i+j+k<=3) continue;
                for(int pl=1; pl<4; pl++)
                {
                    ll temp=1e9;
                    if(pl==1)
                    {
                        if(j>1)
                        temp=min(temp,dp[2][i][j-1][k]+cost(2,j,{i,j,k},i+j+k-3));
                        if(k>1)
                        temp=min(temp,dp[3][i][j][k-1]+cost(3,k,{i,j,k},i+j+k-3));
                    }
                    if(pl==2)
                    {
                        if(i>1)
                        temp=min(temp,dp[1][i-1][j][k]+cost(1,i,{i,j,k},i+j+k-3));
                        if(k>1)
                        temp=min(temp,dp[3][i][j][k-1]+cost(3,k,{i,j,k},i+j+k-3));
                    }
                    if(pl==3)
                    {
                        if(i>1)
                        temp=min(temp,dp[1][i-1][j][k]+cost(1,i,{i,j,k},i+j+k-3));
                        if(j>1)
                        temp=min(temp,dp[2][i][j-1][k]+cost(2,j,{i,j,k},i+j+k-3));
                    }
                    asd=min(asd,temp);
                    dp[pl][i][j][k]=min(temp,dp[pl][i][j][k]);
                }
                sol=asd;
            }
        }
    }
    if(sol==1000000000)
    {
        cout<<"-1";
    }
    else {
        cout<<sol;
    }
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:33:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<st>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for(int i=0; i<cad[1].size(); i++)
      |                  ~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:34:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<st>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for(int j=0; j<cad[2].size(); j++)
      |                      ~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:35:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<st>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |             for(int k=0; k<cad[3].size(); k++)
      |                          ~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:41:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<st>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i=1; i<cad[1].size(); i++)
      |                  ~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<st>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for(int j=1; j<cad[2].size(); j++)
      |                      ~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:45:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<st>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |             for(int k=1; k<cad[3].size(); k++)
      |                          ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 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 348 KB Output is correct
10 Correct 0 ms 356 KB Output is correct
11 Correct 0 ms 356 KB Output is correct
12 Correct 0 ms 356 KB Output is correct
13 Correct 0 ms 356 KB Output is correct
14 Correct 0 ms 356 KB Output is correct
15 Correct 0 ms 356 KB Output is correct
16 Correct 0 ms 356 KB Output is correct
17 Correct 0 ms 356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 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 348 KB Output is correct
10 Correct 0 ms 356 KB Output is correct
11 Correct 0 ms 356 KB Output is correct
12 Correct 0 ms 356 KB Output is correct
13 Correct 0 ms 356 KB Output is correct
14 Correct 0 ms 356 KB Output is correct
15 Correct 0 ms 356 KB Output is correct
16 Correct 0 ms 356 KB Output is correct
17 Correct 0 ms 356 KB Output is correct
18 Correct 1 ms 612 KB Output is correct
19 Correct 1 ms 612 KB Output is correct
20 Correct 1 ms 612 KB Output is correct
21 Correct 1 ms 612 KB Output is correct
22 Correct 1 ms 868 KB Output is correct
23 Correct 1 ms 612 KB Output is correct
24 Correct 1 ms 612 KB Output is correct
25 Correct 0 ms 356 KB Output is correct
26 Correct 1 ms 356 KB Output is correct
27 Correct 1 ms 612 KB Output is correct
28 Correct 1 ms 612 KB Output is correct
29 Correct 1 ms 612 KB Output is correct
30 Correct 1 ms 772 KB Output is correct
31 Correct 1 ms 612 KB Output is correct
32 Correct 1 ms 616 KB Output is correct
33 Correct 0 ms 360 KB Output is correct
34 Correct 1 ms 356 KB Output is correct
35 Correct 1 ms 608 KB Output is correct
36 Correct 1 ms 608 KB Output is correct
37 Correct 1 ms 608 KB Output is correct
38 Correct 1 ms 608 KB Output is correct
39 Correct 1 ms 732 KB Output is correct
40 Correct 0 ms 352 KB Output is correct
41 Correct 1 ms 352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 2908 KB Output is correct
3 Correct 2 ms 2908 KB Output is correct
4 Correct 2 ms 2908 KB Output is correct
5 Correct 2 ms 2908 KB Output is correct
6 Correct 2 ms 2908 KB Output is correct
7 Correct 3 ms 2996 KB Output is correct
8 Correct 3 ms 2792 KB Output is correct
9 Correct 3 ms 2904 KB Output is correct
10 Correct 3 ms 2904 KB Output is correct
11 Correct 2 ms 2908 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1464 KB Output is correct
14 Correct 2 ms 2140 KB Output is correct
15 Correct 3 ms 2904 KB Output is correct
16 Correct 3 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 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 348 KB Output is correct
10 Correct 0 ms 356 KB Output is correct
11 Correct 0 ms 356 KB Output is correct
12 Correct 0 ms 356 KB Output is correct
13 Correct 0 ms 356 KB Output is correct
14 Correct 0 ms 356 KB Output is correct
15 Correct 0 ms 356 KB Output is correct
16 Correct 0 ms 356 KB Output is correct
17 Correct 0 ms 356 KB Output is correct
18 Correct 1 ms 612 KB Output is correct
19 Correct 1 ms 612 KB Output is correct
20 Correct 1 ms 612 KB Output is correct
21 Correct 1 ms 612 KB Output is correct
22 Correct 1 ms 868 KB Output is correct
23 Correct 1 ms 612 KB Output is correct
24 Correct 1 ms 612 KB Output is correct
25 Correct 0 ms 356 KB Output is correct
26 Correct 1 ms 356 KB Output is correct
27 Correct 1 ms 612 KB Output is correct
28 Correct 1 ms 612 KB Output is correct
29 Correct 1 ms 612 KB Output is correct
30 Correct 1 ms 772 KB Output is correct
31 Correct 1 ms 612 KB Output is correct
32 Correct 1 ms 616 KB Output is correct
33 Correct 0 ms 360 KB Output is correct
34 Correct 1 ms 356 KB Output is correct
35 Correct 1 ms 608 KB Output is correct
36 Correct 1 ms 608 KB Output is correct
37 Correct 1 ms 608 KB Output is correct
38 Correct 1 ms 608 KB Output is correct
39 Correct 1 ms 732 KB Output is correct
40 Correct 0 ms 352 KB Output is correct
41 Correct 1 ms 352 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 3 ms 2908 KB Output is correct
44 Correct 2 ms 2908 KB Output is correct
45 Correct 2 ms 2908 KB Output is correct
46 Correct 2 ms 2908 KB Output is correct
47 Correct 2 ms 2908 KB Output is correct
48 Correct 3 ms 2996 KB Output is correct
49 Correct 3 ms 2792 KB Output is correct
50 Correct 3 ms 2904 KB Output is correct
51 Correct 3 ms 2904 KB Output is correct
52 Correct 2 ms 2908 KB Output is correct
53 Correct 1 ms 1116 KB Output is correct
54 Correct 1 ms 1464 KB Output is correct
55 Correct 2 ms 2140 KB Output is correct
56 Correct 3 ms 2904 KB Output is correct
57 Correct 3 ms 2908 KB Output is correct
58 Correct 106 ms 77180 KB Output is correct
59 Correct 113 ms 77364 KB Output is correct
60 Correct 102 ms 76632 KB Output is correct
61 Correct 105 ms 77648 KB Output is correct
62 Correct 12 ms 7768 KB Output is correct
63 Correct 16 ms 12636 KB Output is correct
64 Correct 52 ms 39004 KB Output is correct
65 Correct 75 ms 55296 KB Output is correct
66 Correct 104 ms 76152 KB Output is correct
67 Correct 135 ms 76112 KB Output is correct
68 Correct 105 ms 77412 KB Output is correct
69 Correct 110 ms 77984 KB Output is correct
70 Correct 107 ms 77652 KB Output is correct
71 Correct 102 ms 76008 KB Output is correct
72 Correct 28 ms 20316 KB Output is correct
73 Correct 8 ms 6324 KB Output is correct