답안 #920188

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
920188 2024-02-02T08:22:31 Z ihceker Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
75 / 100
500 ms 145748 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;

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=upper_bound(all(b),a[x])-b.begin();
		ind=min(ind,y);
		int ind2=upper_bound(all(c),a[x])-c.begin();
		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=upper_bound(all(a),b[y])-a.begin();
		ind=min(ind,x);
		int ind2=upper_bound(all(c),b[y])-c.begin();
		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=upper_bound(all(a),c[z])-a.begin();
		ind=min(ind,x);
		int ind2=upper_bound(all(b),c[z])-b.begin();
		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);
		}
	}
	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:15:6: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  if(x==a.size() && y==b.size() && z==c.size())return 0;
      |     ~^~~~~~~~~~
joi2019_ho_t3.cpp:15:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  if(x==a.size() && y==b.size() && z==c.size())return 0;
      |                    ~^~~~~~~~~~
joi2019_ho_t3.cpp:15:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  if(x==a.size() && y==b.size() && z==c.size())return 0;
      |                                   ~^~~~~~~~~~
joi2019_ho_t3.cpp:18:6: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  if(x!=a.size() && t!=1){
      |     ~^~~~~~~~~~
joi2019_ho_t3.cpp:25:6: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  if(y!=b.size() && t!=2){
      |     ~^~~~~~~~~~
joi2019_ho_t3.cpp:32:6: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  if(z!=c.size() && t!=3){
      |     ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 544 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 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 344 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 1 ms 544 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 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 344 KB Output is correct
18 Correct 2 ms 1116 KB Output is correct
19 Correct 2 ms 1116 KB Output is correct
20 Correct 2 ms 1112 KB Output is correct
21 Correct 2 ms 1112 KB Output is correct
22 Correct 2 ms 1112 KB Output is correct
23 Correct 2 ms 1112 KB Output is correct
24 Correct 2 ms 1112 KB Output is correct
25 Correct 1 ms 1112 KB Output is correct
26 Correct 1 ms 856 KB Output is correct
27 Correct 2 ms 1112 KB Output is correct
28 Correct 2 ms 1368 KB Output is correct
29 Correct 2 ms 1116 KB Output is correct
30 Correct 2 ms 1312 KB Output is correct
31 Correct 2 ms 1116 KB Output is correct
32 Correct 3 ms 1368 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 1112 KB Output is correct
37 Correct 1 ms 1112 KB Output is correct
38 Correct 2 ms 1112 KB Output is correct
39 Correct 2 ms 1112 KB Output is correct
40 Correct 1 ms 600 KB Output is correct
41 Correct 1 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 13 ms 13244 KB Output is correct
3 Correct 17 ms 13216 KB Output is correct
4 Correct 13 ms 13472 KB Output is correct
5 Correct 13 ms 13400 KB Output is correct
6 Correct 12 ms 13400 KB Output is correct
7 Correct 13 ms 13148 KB Output is correct
8 Correct 13 ms 13148 KB Output is correct
9 Correct 13 ms 13144 KB Output is correct
10 Correct 13 ms 13404 KB Output is correct
11 Correct 15 ms 13400 KB Output is correct
12 Correct 4 ms 3928 KB Output is correct
13 Correct 6 ms 6488 KB Output is correct
14 Correct 9 ms 9508 KB Output is correct
15 Correct 13 ms 13400 KB Output is correct
16 Correct 13 ms 13404 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 1 ms 544 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 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 344 KB Output is correct
18 Correct 2 ms 1116 KB Output is correct
19 Correct 2 ms 1116 KB Output is correct
20 Correct 2 ms 1112 KB Output is correct
21 Correct 2 ms 1112 KB Output is correct
22 Correct 2 ms 1112 KB Output is correct
23 Correct 2 ms 1112 KB Output is correct
24 Correct 2 ms 1112 KB Output is correct
25 Correct 1 ms 1112 KB Output is correct
26 Correct 1 ms 856 KB Output is correct
27 Correct 2 ms 1112 KB Output is correct
28 Correct 2 ms 1368 KB Output is correct
29 Correct 2 ms 1116 KB Output is correct
30 Correct 2 ms 1312 KB Output is correct
31 Correct 2 ms 1116 KB Output is correct
32 Correct 3 ms 1368 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 1112 KB Output is correct
37 Correct 1 ms 1112 KB Output is correct
38 Correct 2 ms 1112 KB Output is correct
39 Correct 2 ms 1112 KB Output is correct
40 Correct 1 ms 600 KB Output is correct
41 Correct 1 ms 856 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 13 ms 13244 KB Output is correct
44 Correct 17 ms 13216 KB Output is correct
45 Correct 13 ms 13472 KB Output is correct
46 Correct 13 ms 13400 KB Output is correct
47 Correct 12 ms 13400 KB Output is correct
48 Correct 13 ms 13148 KB Output is correct
49 Correct 13 ms 13148 KB Output is correct
50 Correct 13 ms 13144 KB Output is correct
51 Correct 13 ms 13404 KB Output is correct
52 Correct 15 ms 13400 KB Output is correct
53 Correct 4 ms 3928 KB Output is correct
54 Correct 6 ms 6488 KB Output is correct
55 Correct 9 ms 9508 KB Output is correct
56 Correct 13 ms 13400 KB Output is correct
57 Correct 13 ms 13404 KB Output is correct
58 Correct 487 ms 145488 KB Output is correct
59 Execution timed out 504 ms 145748 KB Time limit exceeded
60 Halted 0 ms 0 KB -