Submission #920193

# Submission time Handle Problem Language Result Execution time Memory
920193 2024-02-02T08:30:07 Z ihceker Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
291 ms 147028 KB
#include<bits/stdc++.h>
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int pre[405][2],pre2[405][2],pre3[405][2];
vector<int>a,b,c;
vector<vector<vector<vector<int>>>>dp;

inline int f(int x,int y,int z,int t){
	if(x==a.size() && y==b.size() && z==c.size())return 0;
	if(dp[x][y][z][t]!=-1)return dp[x][y][z][t];
	int mn=1e9;
	if(x!=a.size() && t!=1){
		int ind=pre[x][0];
		ind=min(ind,y);
		int ind2=pre[x][1];
		ind2=min(ind2,z);
		mn=min(mn,f(x+1,y,z,1)+y-ind+z-ind2);
	}
	if(y!=b.size() && t!=2){
		int ind=pre2[y][0];
		ind=min(ind,x);
		int ind2=pre2[y][1];
		ind2=min(ind2,z);
		mn=min(mn,f(x,y+1,z,2)+x-ind+z-ind2);
	}
	if(z!=c.size() && t!=3){
		int ind=pre3[z][0];
		ind=min(ind,x);
		int ind2=pre3[z][1];
		ind2=min(ind2,y);
		mn=min(mn,f(x,y,z+1,3)+x-ind+y-ind2);
	}
	return dp[x][y][z][t]=mn;
}

int32_t main(){
	fast;
	int n;
	cin>>n;
	string s;
	cin>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='R'){
			a.pb(i);
		}
		if(s[i]=='G'){
			b.pb(i);
		}
		if(s[i]=='Y'){
			c.pb(i);
		}
	}
	for(int i=0;i<a.size();i++){
		pre[i][0]=upper_bound(all(b),a[i])-b.begin();
		pre[i][1]=upper_bound(all(c),a[i])-c.begin();
	}
	for(int i=0;i<b.size();i++){
		pre2[i][0]=upper_bound(all(a),b[i])-a.begin();
		pre2[i][1]=upper_bound(all(c),b[i])-c.begin();
	}
	for(int i=0;i<c.size();i++){
		pre3[i][0]=upper_bound(all(a),c[i])-a.begin();
		pre3[i][1]=upper_bound(all(b),c[i])-b.begin();
	}
	dp.assign((int)a.size()+5,vector<vector<vector<int>>>((int)b.size()+5,vector<vector<int>>((int)c.size()+5,vector<int>(4,-1))));
	int ans=f(0,0,0,0);
	if(ans==1e9)cout<<-1<<endl;
	else cout<<ans<<endl;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int f(int, int, int, int)':
joi2019_ho_t3.cpp:16:6: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  if(x==a.size() && y==b.size() && z==c.size())return 0;
      |     ~^~~~~~~~~~
joi2019_ho_t3.cpp:16:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  if(x==a.size() && y==b.size() && z==c.size())return 0;
      |                    ~^~~~~~~~~~
joi2019_ho_t3.cpp:16:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  if(x==a.size() && y==b.size() && z==c.size())return 0;
      |                                   ~^~~~~~~~~~
joi2019_ho_t3.cpp:19:6: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |  if(x!=a.size() && t!=1){
      |     ~^~~~~~~~~~
joi2019_ho_t3.cpp:26:6: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  if(y!=b.size() && t!=2){
      |     ~^~~~~~~~~~
joi2019_ho_t3.cpp:33:6: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |  if(z!=c.size() && t!=3){
      |     ~^~~~~~~~~~
joi2019_ho_t3.cpp: In function 'int32_t main()':
joi2019_ho_t3.cpp:60:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |  for(int i=0;i<a.size();i++){
      |              ~^~~~~~~~~
joi2019_ho_t3.cpp:64:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |  for(int i=0;i<b.size();i++){
      |              ~^~~~~~~~~
joi2019_ho_t3.cpp:68:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |  for(int i=0;i<c.size();i++){
      |              ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 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 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 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 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 1368 KB Output is correct
19 Correct 2 ms 1112 KB Output is correct
20 Correct 2 ms 1112 KB Output is correct
21 Correct 1 ms 1368 KB Output is correct
22 Correct 1 ms 1112 KB Output is correct
23 Correct 2 ms 1368 KB Output is correct
24 Correct 1 ms 1112 KB Output is correct
25 Correct 1 ms 856 KB Output is correct
26 Correct 1 ms 856 KB Output is correct
27 Correct 1 ms 1112 KB Output is correct
28 Correct 1 ms 1372 KB Output is correct
29 Correct 1 ms 1368 KB Output is correct
30 Correct 1 ms 1368 KB Output is correct
31 Correct 1 ms 1116 KB Output is correct
32 Correct 2 ms 1116 KB Output is correct
33 Correct 1 ms 856 KB Output is correct
34 Correct 1 ms 856 KB Output is correct
35 Correct 2 ms 1112 KB Output is correct
36 Correct 2 ms 1116 KB Output is correct
37 Correct 1 ms 1116 KB Output is correct
38 Correct 1 ms 1112 KB Output is correct
39 Correct 2 ms 1368 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 15 ms 13404 KB Output is correct
3 Correct 13 ms 13144 KB Output is correct
4 Correct 14 ms 13400 KB Output is correct
5 Correct 13 ms 13208 KB Output is correct
6 Correct 14 ms 13404 KB Output is correct
7 Correct 13 ms 13144 KB Output is correct
8 Correct 13 ms 13144 KB Output is correct
9 Correct 13 ms 13144 KB Output is correct
10 Correct 13 ms 13400 KB Output is correct
11 Correct 14 ms 13228 KB Output is correct
12 Correct 4 ms 3928 KB Output is correct
13 Correct 6 ms 6488 KB Output is correct
14 Correct 10 ms 9304 KB Output is correct
15 Correct 13 ms 13400 KB Output is correct
16 Correct 13 ms 13400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 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 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 1368 KB Output is correct
19 Correct 2 ms 1112 KB Output is correct
20 Correct 2 ms 1112 KB Output is correct
21 Correct 1 ms 1368 KB Output is correct
22 Correct 1 ms 1112 KB Output is correct
23 Correct 2 ms 1368 KB Output is correct
24 Correct 1 ms 1112 KB Output is correct
25 Correct 1 ms 856 KB Output is correct
26 Correct 1 ms 856 KB Output is correct
27 Correct 1 ms 1112 KB Output is correct
28 Correct 1 ms 1372 KB Output is correct
29 Correct 1 ms 1368 KB Output is correct
30 Correct 1 ms 1368 KB Output is correct
31 Correct 1 ms 1116 KB Output is correct
32 Correct 2 ms 1116 KB Output is correct
33 Correct 1 ms 856 KB Output is correct
34 Correct 1 ms 856 KB Output is correct
35 Correct 2 ms 1112 KB Output is correct
36 Correct 2 ms 1116 KB Output is correct
37 Correct 1 ms 1116 KB Output is correct
38 Correct 1 ms 1112 KB Output is correct
39 Correct 2 ms 1368 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 856 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 15 ms 13404 KB Output is correct
44 Correct 13 ms 13144 KB Output is correct
45 Correct 14 ms 13400 KB Output is correct
46 Correct 13 ms 13208 KB Output is correct
47 Correct 14 ms 13404 KB Output is correct
48 Correct 13 ms 13144 KB Output is correct
49 Correct 13 ms 13144 KB Output is correct
50 Correct 13 ms 13144 KB Output is correct
51 Correct 13 ms 13400 KB Output is correct
52 Correct 14 ms 13228 KB Output is correct
53 Correct 4 ms 3928 KB Output is correct
54 Correct 6 ms 6488 KB Output is correct
55 Correct 10 ms 9304 KB Output is correct
56 Correct 13 ms 13400 KB Output is correct
57 Correct 13 ms 13400 KB Output is correct
58 Correct 270 ms 145488 KB Output is correct
59 Correct 256 ms 145736 KB Output is correct
60 Correct 270 ms 144464 KB Output is correct
61 Correct 291 ms 146220 KB Output is correct
62 Correct 23 ms 21852 KB Output is correct
63 Correct 31 ms 30648 KB Output is correct
64 Correct 101 ms 77440 KB Output is correct
65 Correct 169 ms 107332 KB Output is correct
66 Correct 261 ms 144100 KB Output is correct
67 Correct 279 ms 144428 KB Output is correct
68 Correct 284 ms 145980 KB Output is correct
69 Correct 274 ms 147028 KB Output is correct
70 Correct 283 ms 146512 KB Output is correct
71 Correct 266 ms 143440 KB Output is correct
72 Correct 47 ms 41552 KB Output is correct
73 Correct 19 ms 18264 KB Output is correct