Submission #947849

# Submission time Handle Problem Language Result Execution time Memory
947849 2024-03-17T06:35:49 Z vjudge306 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
75 / 100
500 ms 135516 KB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
#define nn "\n"
#define x_x ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define intt int _; cin >> _; while (_--)
#define emp push_back
#define mod 1000000007
#define all(v) v.begin(), v.end()
#define ld long double
#define A first
#define B second
typedef long long ll;
const ld eps = 1e-27;
// diff between decimals 0.000000001 mt19937 mt(time(nullptr));
int dp[205][205][205][4], ar[405]; int n; string s; int R,G,Y;
int ans(int y, int r, int g) {
int i=r+g+y;
if(i>=n) return 0;

int k=3; if(i) k=ar[i-1];

if(i&&~dp[y][r][g][k]) return dp[y][r][g][k];

int fans=2000000;
int mx=max({(k==1)+R-r, (k==2)+G-g, (k==0)+Y-y}), sm=(k!=3)+(n-i)-mx; --mx;
if (mx>sm)
    return dp[y][r][g][k]=fans;

for(int z=0; z<3; z++) {
if(z==k) continue;
int j=i;
while(j<n&&ar[j]!=z) ++j;
if (j<n) {
int nm=0;
if(z==1)r++; else if(z==2)g++; else y++;
for (int x=j; x>i; x-=1) swap(ar[x], ar[x-1]), ++nm;
fans=min(fans,nm+ans(y,r,g));
for(int x=i; x<j; x++)swap(ar[x], ar[x+1]);

if(z==1)r-=1; else if(z==2)g-=1; else y-=1;
}
}
return dp[y][r][g][k]=fans;
}
int main() {

    x_x
 cin>>n>>s; int a=0,b=0,c=0;
for(int i=0; i<n; i++) {
if(s[i]=='R')a++, ar[i]=1; else if(s[i]=='G')b++, ar[i]=2;
else ar[i]=0, c++;
}
R=a, G=b, Y=c;
a=max({a,b,c}), b=n-a; --a;
//if(a>b) return cout<<-1, 0;
memset(dp,-1,sizeof(dp)); a=ans(0,0,0);
cout<<(a>=2000000?-1:a);
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 43 ms 135260 KB Output is correct
2 Correct 33 ms 135108 KB Output is correct
3 Correct 33 ms 135508 KB Output is correct
4 Correct 34 ms 135304 KB Output is correct
5 Correct 34 ms 135248 KB Output is correct
6 Correct 33 ms 135248 KB Output is correct
7 Correct 34 ms 135100 KB Output is correct
8 Correct 33 ms 135260 KB Output is correct
9 Correct 33 ms 135172 KB Output is correct
10 Correct 35 ms 135252 KB Output is correct
11 Correct 33 ms 135164 KB Output is correct
12 Correct 33 ms 135252 KB Output is correct
13 Correct 33 ms 135244 KB Output is correct
14 Correct 33 ms 135256 KB Output is correct
15 Correct 33 ms 135256 KB Output is correct
16 Correct 33 ms 135060 KB Output is correct
17 Correct 33 ms 135256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 135260 KB Output is correct
2 Correct 33 ms 135108 KB Output is correct
3 Correct 33 ms 135508 KB Output is correct
4 Correct 34 ms 135304 KB Output is correct
5 Correct 34 ms 135248 KB Output is correct
6 Correct 33 ms 135248 KB Output is correct
7 Correct 34 ms 135100 KB Output is correct
8 Correct 33 ms 135260 KB Output is correct
9 Correct 33 ms 135172 KB Output is correct
10 Correct 35 ms 135252 KB Output is correct
11 Correct 33 ms 135164 KB Output is correct
12 Correct 33 ms 135252 KB Output is correct
13 Correct 33 ms 135244 KB Output is correct
14 Correct 33 ms 135256 KB Output is correct
15 Correct 33 ms 135256 KB Output is correct
16 Correct 33 ms 135060 KB Output is correct
17 Correct 33 ms 135256 KB Output is correct
18 Correct 34 ms 135256 KB Output is correct
19 Correct 35 ms 135256 KB Output is correct
20 Correct 33 ms 135148 KB Output is correct
21 Correct 34 ms 135252 KB Output is correct
22 Correct 38 ms 135484 KB Output is correct
23 Correct 35 ms 135260 KB Output is correct
24 Correct 33 ms 135244 KB Output is correct
25 Correct 33 ms 135248 KB Output is correct
26 Correct 33 ms 135260 KB Output is correct
27 Correct 34 ms 135228 KB Output is correct
28 Correct 34 ms 135260 KB Output is correct
29 Correct 35 ms 135476 KB Output is correct
30 Correct 34 ms 135208 KB Output is correct
31 Correct 34 ms 135260 KB Output is correct
32 Correct 33 ms 135252 KB Output is correct
33 Correct 33 ms 135248 KB Output is correct
34 Correct 37 ms 135260 KB Output is correct
35 Correct 34 ms 135260 KB Output is correct
36 Correct 34 ms 135292 KB Output is correct
37 Correct 33 ms 135256 KB Output is correct
38 Correct 34 ms 135132 KB Output is correct
39 Correct 36 ms 135248 KB Output is correct
40 Correct 33 ms 135244 KB Output is correct
41 Correct 33 ms 135248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 135248 KB Output is correct
2 Correct 36 ms 135232 KB Output is correct
3 Correct 34 ms 135308 KB Output is correct
4 Correct 34 ms 135292 KB Output is correct
5 Correct 35 ms 135188 KB Output is correct
6 Correct 34 ms 135160 KB Output is correct
7 Correct 35 ms 135516 KB Output is correct
8 Correct 34 ms 135256 KB Output is correct
9 Correct 34 ms 135256 KB Output is correct
10 Correct 35 ms 135256 KB Output is correct
11 Correct 34 ms 135264 KB Output is correct
12 Correct 35 ms 135440 KB Output is correct
13 Correct 34 ms 135248 KB Output is correct
14 Correct 38 ms 135256 KB Output is correct
15 Correct 35 ms 135256 KB Output is correct
16 Correct 34 ms 135256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 135260 KB Output is correct
2 Correct 33 ms 135108 KB Output is correct
3 Correct 33 ms 135508 KB Output is correct
4 Correct 34 ms 135304 KB Output is correct
5 Correct 34 ms 135248 KB Output is correct
6 Correct 33 ms 135248 KB Output is correct
7 Correct 34 ms 135100 KB Output is correct
8 Correct 33 ms 135260 KB Output is correct
9 Correct 33 ms 135172 KB Output is correct
10 Correct 35 ms 135252 KB Output is correct
11 Correct 33 ms 135164 KB Output is correct
12 Correct 33 ms 135252 KB Output is correct
13 Correct 33 ms 135244 KB Output is correct
14 Correct 33 ms 135256 KB Output is correct
15 Correct 33 ms 135256 KB Output is correct
16 Correct 33 ms 135060 KB Output is correct
17 Correct 33 ms 135256 KB Output is correct
18 Correct 34 ms 135256 KB Output is correct
19 Correct 35 ms 135256 KB Output is correct
20 Correct 33 ms 135148 KB Output is correct
21 Correct 34 ms 135252 KB Output is correct
22 Correct 38 ms 135484 KB Output is correct
23 Correct 35 ms 135260 KB Output is correct
24 Correct 33 ms 135244 KB Output is correct
25 Correct 33 ms 135248 KB Output is correct
26 Correct 33 ms 135260 KB Output is correct
27 Correct 34 ms 135228 KB Output is correct
28 Correct 34 ms 135260 KB Output is correct
29 Correct 35 ms 135476 KB Output is correct
30 Correct 34 ms 135208 KB Output is correct
31 Correct 34 ms 135260 KB Output is correct
32 Correct 33 ms 135252 KB Output is correct
33 Correct 33 ms 135248 KB Output is correct
34 Correct 37 ms 135260 KB Output is correct
35 Correct 34 ms 135260 KB Output is correct
36 Correct 34 ms 135292 KB Output is correct
37 Correct 33 ms 135256 KB Output is correct
38 Correct 34 ms 135132 KB Output is correct
39 Correct 36 ms 135248 KB Output is correct
40 Correct 33 ms 135244 KB Output is correct
41 Correct 33 ms 135248 KB Output is correct
42 Correct 36 ms 135248 KB Output is correct
43 Correct 36 ms 135232 KB Output is correct
44 Correct 34 ms 135308 KB Output is correct
45 Correct 34 ms 135292 KB Output is correct
46 Correct 35 ms 135188 KB Output is correct
47 Correct 34 ms 135160 KB Output is correct
48 Correct 35 ms 135516 KB Output is correct
49 Correct 34 ms 135256 KB Output is correct
50 Correct 34 ms 135256 KB Output is correct
51 Correct 35 ms 135256 KB Output is correct
52 Correct 34 ms 135264 KB Output is correct
53 Correct 35 ms 135440 KB Output is correct
54 Correct 34 ms 135248 KB Output is correct
55 Correct 38 ms 135256 KB Output is correct
56 Correct 35 ms 135256 KB Output is correct
57 Correct 34 ms 135256 KB Output is correct
58 Correct 280 ms 135352 KB Output is correct
59 Correct 278 ms 135352 KB Output is correct
60 Correct 283 ms 135356 KB Output is correct
61 Correct 297 ms 135512 KB Output is correct
62 Correct 35 ms 135252 KB Output is correct
63 Correct 42 ms 135252 KB Output is correct
64 Correct 121 ms 135356 KB Output is correct
65 Correct 186 ms 135356 KB Output is correct
66 Execution timed out 562 ms 135348 KB Time limit exceeded
67 Halted 0 ms 0 KB -