답안 #870452

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
870452 2023-11-08T02:13:36 Z LeVanThuc Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
100 / 100
315 ms 755280 KB
#include<bits/stdc++.h>
using namespace std;
#define ll int
#define fi first
#define se second
#define p(x,y) pair<ll,ll>(x,y)
#define BIT(i,x) ((x>>i)&1)
#define MASK(x) (1<<x)
#define ld long double
#define __builtin_popcount __builtin_popcountll
#define pll pair<ll,ll>
template<class T1,class T2>
bool maximize(T1 &x,const T2 &y)
{
    if(x<y)
    {
        x=y;
        return 1;
    }
    return 0;
}
template<class T1,class T2>
bool minimize(T1 &x,const T2 &y)
{
    if(x>y)
    {
        x=y;
        return 1;
    }
    return 0;
}
void online()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef thuc
    freopen("input.INP","r",stdin);
    freopen("output.OUT","w",stdout);
#else

#endif
}
const ll N=400;
ll f[N][N][N][3],n;
vector<ll> vt[3];
ll lg[4][4][N+2][N+2];
string s;
void solve(ll x,ll y)
{
    for(int i=0;i<vt[x].size();i++)
    {
        for(int j=0;j<=vt[y].size();j++)
        {
            if(j>0)
            lg[x][y][i][j]+=(vt[x][i]>vt[y][j-1]);
            lg[x][y][i][j+1]+=lg[x][y][i][j];
        }
    }
}
ll dp(ll i,ll j,ll k,ll pre)
{
    if(i==vt[0].size()&&j==vt[1].size()&&k==vt[2].size()) return 0;
    ll &res=f[i][j][k][pre];
    if(res!=-1) return res;
    res=1e9;
    if(pre!=0&&i<vt[0].size())
    {
        minimize(res,dp(i+1,j,k,0)+vt[0][i]-i-lg[0][1][i][j]-lg[0][2][i][k]);
    }
    if(pre!=1&&j<vt[1].size())
    {
        minimize(res,dp(i,j+1,k,1)+vt[1][j]-j-lg[1][0][j][i]-lg[1][2][j][k]);
    }
    if(pre!=2&&k<vt[2].size())
    {
        minimize(res,dp(i,j,k+1,2)+vt[2][k]-k-lg[2][0][k][i]-lg[2][1][k][j]);
    }
    return res;
}
int main()
{
    online();
    cin>>n;
    cin>>s;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='R') vt[0].push_back(i);
        if(s[i]=='G') vt[1].push_back(i);
        if(s[i]=='Y') vt[2].push_back(i);
    }
    solve(0,1);
    solve(0,2);
    solve(1,0);
    solve(1,2);
    solve(2,0);
    solve(2,1);
    memset(f,-1,sizeof f);
    ll z=min(dp(0,0,0,0),min(dp(0,0,0,1),dp(0,0,0,2)));
    if(z>=1e9)
    {
        z=-1;
    }
    cout<<z;
}

Compilation message

joi2019_ho_t3.cpp: In function 'void solve(int, int)':
joi2019_ho_t3.cpp:50:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(int i=0;i<vt[x].size();i++)
      |                 ~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for(int j=0;j<=vt[y].size();j++)
      |                     ~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp: In function 'int dp(int, int, int, int)':
joi2019_ho_t3.cpp:62:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     if(i==vt[0].size()&&j==vt[1].size()&&k==vt[2].size()) return 0;
      |        ~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:62:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     if(i==vt[0].size()&&j==vt[1].size()&&k==vt[2].size()) return 0;
      |                         ~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:62:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     if(i==vt[0].size()&&j==vt[1].size()&&k==vt[2].size()) return 0;
      |                                          ~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:66:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     if(pre!=0&&i<vt[0].size())
      |                ~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:70:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     if(pre!=1&&j<vt[1].size())
      |                ~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:74:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     if(pre!=2&&k<vt[2].size())
      |                ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 315 ms 753572 KB Output is correct
2 Correct 247 ms 753644 KB Output is correct
3 Correct 215 ms 753488 KB Output is correct
4 Correct 164 ms 753456 KB Output is correct
5 Correct 152 ms 753492 KB Output is correct
6 Correct 145 ms 753492 KB Output is correct
7 Correct 142 ms 753492 KB Output is correct
8 Correct 139 ms 753684 KB Output is correct
9 Correct 149 ms 753472 KB Output is correct
10 Correct 135 ms 753492 KB Output is correct
11 Correct 131 ms 753536 KB Output is correct
12 Correct 123 ms 753652 KB Output is correct
13 Correct 129 ms 753572 KB Output is correct
14 Correct 118 ms 753520 KB Output is correct
15 Correct 87 ms 753492 KB Output is correct
16 Correct 85 ms 753680 KB Output is correct
17 Correct 88 ms 753928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 315 ms 753572 KB Output is correct
2 Correct 247 ms 753644 KB Output is correct
3 Correct 215 ms 753488 KB Output is correct
4 Correct 164 ms 753456 KB Output is correct
5 Correct 152 ms 753492 KB Output is correct
6 Correct 145 ms 753492 KB Output is correct
7 Correct 142 ms 753492 KB Output is correct
8 Correct 139 ms 753684 KB Output is correct
9 Correct 149 ms 753472 KB Output is correct
10 Correct 135 ms 753492 KB Output is correct
11 Correct 131 ms 753536 KB Output is correct
12 Correct 123 ms 753652 KB Output is correct
13 Correct 129 ms 753572 KB Output is correct
14 Correct 118 ms 753520 KB Output is correct
15 Correct 87 ms 753492 KB Output is correct
16 Correct 85 ms 753680 KB Output is correct
17 Correct 88 ms 753928 KB Output is correct
18 Correct 88 ms 753732 KB Output is correct
19 Correct 85 ms 753752 KB Output is correct
20 Correct 85 ms 753748 KB Output is correct
21 Correct 85 ms 753656 KB Output is correct
22 Correct 87 ms 753852 KB Output is correct
23 Correct 85 ms 753744 KB Output is correct
24 Correct 84 ms 753784 KB Output is correct
25 Correct 84 ms 753744 KB Output is correct
26 Correct 84 ms 753604 KB Output is correct
27 Correct 85 ms 753744 KB Output is correct
28 Correct 85 ms 753748 KB Output is correct
29 Correct 84 ms 753748 KB Output is correct
30 Correct 83 ms 753836 KB Output is correct
31 Correct 83 ms 753628 KB Output is correct
32 Correct 84 ms 753748 KB Output is correct
33 Correct 88 ms 753744 KB Output is correct
34 Correct 85 ms 753748 KB Output is correct
35 Correct 83 ms 753676 KB Output is correct
36 Correct 84 ms 753800 KB Output is correct
37 Correct 84 ms 753748 KB Output is correct
38 Correct 83 ms 753744 KB Output is correct
39 Correct 85 ms 753744 KB Output is correct
40 Correct 87 ms 753868 KB Output is correct
41 Correct 89 ms 753748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 753596 KB Output is correct
2 Correct 84 ms 754832 KB Output is correct
3 Correct 83 ms 754936 KB Output is correct
4 Correct 84 ms 754832 KB Output is correct
5 Correct 87 ms 754740 KB Output is correct
6 Correct 82 ms 754936 KB Output is correct
7 Correct 86 ms 754768 KB Output is correct
8 Correct 84 ms 754904 KB Output is correct
9 Correct 88 ms 754768 KB Output is correct
10 Correct 86 ms 754864 KB Output is correct
11 Correct 84 ms 754792 KB Output is correct
12 Correct 88 ms 754288 KB Output is correct
13 Correct 83 ms 754492 KB Output is correct
14 Correct 84 ms 754516 KB Output is correct
15 Correct 83 ms 754884 KB Output is correct
16 Correct 86 ms 754768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 315 ms 753572 KB Output is correct
2 Correct 247 ms 753644 KB Output is correct
3 Correct 215 ms 753488 KB Output is correct
4 Correct 164 ms 753456 KB Output is correct
5 Correct 152 ms 753492 KB Output is correct
6 Correct 145 ms 753492 KB Output is correct
7 Correct 142 ms 753492 KB Output is correct
8 Correct 139 ms 753684 KB Output is correct
9 Correct 149 ms 753472 KB Output is correct
10 Correct 135 ms 753492 KB Output is correct
11 Correct 131 ms 753536 KB Output is correct
12 Correct 123 ms 753652 KB Output is correct
13 Correct 129 ms 753572 KB Output is correct
14 Correct 118 ms 753520 KB Output is correct
15 Correct 87 ms 753492 KB Output is correct
16 Correct 85 ms 753680 KB Output is correct
17 Correct 88 ms 753928 KB Output is correct
18 Correct 88 ms 753732 KB Output is correct
19 Correct 85 ms 753752 KB Output is correct
20 Correct 85 ms 753748 KB Output is correct
21 Correct 85 ms 753656 KB Output is correct
22 Correct 87 ms 753852 KB Output is correct
23 Correct 85 ms 753744 KB Output is correct
24 Correct 84 ms 753784 KB Output is correct
25 Correct 84 ms 753744 KB Output is correct
26 Correct 84 ms 753604 KB Output is correct
27 Correct 85 ms 753744 KB Output is correct
28 Correct 85 ms 753748 KB Output is correct
29 Correct 84 ms 753748 KB Output is correct
30 Correct 83 ms 753836 KB Output is correct
31 Correct 83 ms 753628 KB Output is correct
32 Correct 84 ms 753748 KB Output is correct
33 Correct 88 ms 753744 KB Output is correct
34 Correct 85 ms 753748 KB Output is correct
35 Correct 83 ms 753676 KB Output is correct
36 Correct 84 ms 753800 KB Output is correct
37 Correct 84 ms 753748 KB Output is correct
38 Correct 83 ms 753744 KB Output is correct
39 Correct 85 ms 753744 KB Output is correct
40 Correct 87 ms 753868 KB Output is correct
41 Correct 89 ms 753748 KB Output is correct
42 Correct 85 ms 753596 KB Output is correct
43 Correct 84 ms 754832 KB Output is correct
44 Correct 83 ms 754936 KB Output is correct
45 Correct 84 ms 754832 KB Output is correct
46 Correct 87 ms 754740 KB Output is correct
47 Correct 82 ms 754936 KB Output is correct
48 Correct 86 ms 754768 KB Output is correct
49 Correct 84 ms 754904 KB Output is correct
50 Correct 88 ms 754768 KB Output is correct
51 Correct 86 ms 754864 KB Output is correct
52 Correct 84 ms 754792 KB Output is correct
53 Correct 88 ms 754288 KB Output is correct
54 Correct 83 ms 754492 KB Output is correct
55 Correct 84 ms 754516 KB Output is correct
56 Correct 83 ms 754884 KB Output is correct
57 Correct 86 ms 754768 KB Output is correct
58 Correct 158 ms 754776 KB Output is correct
59 Correct 143 ms 754772 KB Output is correct
60 Correct 141 ms 754768 KB Output is correct
61 Correct 150 ms 754936 KB Output is correct
62 Correct 84 ms 754772 KB Output is correct
63 Correct 84 ms 754772 KB Output is correct
64 Correct 93 ms 754904 KB Output is correct
65 Correct 111 ms 755280 KB Output is correct
66 Correct 145 ms 754852 KB Output is correct
67 Correct 141 ms 754964 KB Output is correct
68 Correct 141 ms 754804 KB Output is correct
69 Correct 149 ms 754836 KB Output is correct
70 Correct 147 ms 754960 KB Output is correct
71 Correct 144 ms 754772 KB Output is correct
72 Correct 85 ms 754768 KB Output is correct
73 Correct 86 ms 754768 KB Output is correct