Submission #922205

# Submission time Handle Problem Language Result Execution time Memory
922205 2024-02-05T08:37:21 Z tolbi Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
75 / 100
500 ms 18264 KB
#pragma optimize("Bismillahirrahmanirrahim")
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█■█
//█─█─█▄─█▄─█─█─█─█
//Allahuekber
//ahmet23 orz...
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//YavuzSultanSelimHan
//AbdulhamidHan
#define author tolbi
#include <bits/stdc++.h>
using namespace std;
template<typename X, typename Y> istream& operator>>(istream& in, pair<X,Y> &pr) {return in>>pr.first>>pr.second;}
template<typename X, typename Y> ostream& operator<<(ostream& os, pair<X,Y> pr) {return os<<pr.first<<" "<<pr.second;}
template<typename X> istream& operator>>(istream& in, vector<X> &arr) {for(auto &it : arr) in>>it; return in;}
template<typename X> ostream& operator<<(ostream& os, vector<X> arr) {for(auto &it : arr) os<<it<<" "; return os;}
template<typename X, size_t Y> istream& operator>>(istream& in, array<X,Y> &arr) {for(auto &it : arr) in>>it; return in;}
template<typename X, size_t Y> ostream& operator<<(ostream& os, array<X,Y> arr) {for(auto &it : arr) os<<it<<" "; return os;}
#define int long long
#define endl '\n'
#define vint(x) vector<int> x
#define deci(x) int x;cin>>x;
#define decstr(x) string x;cin>>x;
#define cinarr(x) for (auto &it : x) cin>>it;
#define coutarr(x) for (auto &it : x) cout<<it<<" ";cout<<endl;
#define sortarr(x) sort(x.begin(),x.end())
#define sortrarr(x) sort(x.rbegin(),x.rend())
#define det(x) cout<<"NO\0YES"+x*3<<endl;
#define INF LONG_LONG_MAX
#define rev(x) reverse(x.begin(),x.end());
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define tol(bi) (1LL<<((int)(bi)))
const int MOD = 1e9+7;
mt19937 ayahya(chrono::high_resolution_clock().now().time_since_epoch().count());
int32_t main(){
	ios;
	int t=1;
	int tno = 0;
	if (!t) cin>>t;
	while (t-(tno++)){
		deci(n);
		decstr(str);
		vector<int> r;
		vector<int> g;
		vector<int> y;
		for (int i = 0; i < n; ++i)
		{
			if (str[i]=='R') r.push_back(i);
			else if (str[i]=='G') g.push_back(i);
			else y.push_back(i);
		}
		vector<vector<vector<int>>> old(n+1,vector<vector<int>>(n+1,vector<int>(3,-1)));
		vector<vector<vector<int>>> dp(n+1,vector<vector<int>>(n+1,vector<int>(3,-1)));
		old[r.size()][g.size()][0]=0;
		old[r.size()][g.size()][1]=0;
		old[r.size()][g.size()][2]=0;
		for (int i = n-1; i >= 0; i--){
			for (int j = 0; j < n; j++){
				for (int k = 0; k < n; k++){
					for (int z = 0; z < 3; z++){
						dp[j][k][z]=MOD;
						if (j>r.size() || k>g.size() || (i-j-k)>y.size()) continue;
						if (j>i || k>i || (i-j-k)>i) continue;
						if (j+k+y.size()<i) continue;
						if (z==0 && j<r.size() && old[j+1][k][1]!=-1){
							int lb = 0;
							lb+=max(0ll,lower_bound(g.begin(), g.end(), r[j])-g.begin()-k);
							lb+=max(0ll,lower_bound(y.begin(), y.end(), r[j])-y.begin()-(i-j-k));
							dp[j][k][z]=min(dp[j][k][z],old[j+1][k][1]+lb);
						}
						if (z==0 && j<r.size() && old[j+1][k][2]!=-1){
							int lb = 0;
							lb+=max(0ll,lower_bound(g.begin(), g.end(), r[j])-g.begin()-k);
							lb+=max(0ll,lower_bound(y.begin(), y.end(), r[j])-y.begin()-(i-j-k));
							dp[j][k][z]=min(dp[j][k][z],old[j+1][k][2]+lb);
						}
						if (z==1 && k<g.size() && old[j][k+1][0]!=-1){
							int lb = 0;
							lb+=max(0ll,lower_bound(r.begin(), r.end(), g[k])-r.begin()-j);
							lb+=max(0ll,lower_bound(y.begin(), y.end(), g[k])-y.begin()-(i-j-k));
							dp[j][k][z]=min(dp[j][k][z],old[j][k+1][0]+lb);
						}
						if (z==1 && k<g.size() && old[j][k+1][2]!=-1){
							int lb = 0;
							lb+=max(0ll,lower_bound(r.begin(), r.end(), g[k])-r.begin()-j);
							lb+=max(0ll,lower_bound(y.begin(), y.end(), g[k])-y.begin()-(i-j-k));
							dp[j][k][z]=min(dp[j][k][z],old[j][k+1][2]+lb);
						}
						if (z==2 && i-j-k<y.size() && old[j][k][0]!=-1){
							int lb = 0;
							lb+=max(0ll,lower_bound(r.begin(), r.end(), y[i-j-k])-r.begin()-j);
							lb+=max(0ll,lower_bound(g.begin(), g.end(), y[i-j-k])-g.begin()-k);
							dp[j][k][z]=min(dp[j][k][z],old[j][k][0]+lb);
						}
						if (z==2 && i-j-k<y.size() && old[j][k][1]!=-1){
							int lb = 0;
							lb+=max(0ll,lower_bound(r.begin(), r.end(), y[i-j-k])-r.begin()-j);
							lb+=max(0ll,lower_bound(g.begin(), g.end(), y[i-j-k])-g.begin()-k);
							dp[j][k][z]=min(dp[j][k][z],old[j][k][1]+lb);
						}
						if (dp[j][k][z]==MOD) dp[j][k][z]=-1;
					}
				}
			}
			swap(old,dp);
		}
		int ans = -1;
		for (int i = 0; i < 3; ++i)
		{
			if (old[0][0][i]!=-1){
				if (ans==-1) ans=old[0][0][i];
				ans=min(ans,old[0][0][i]);
			}
		}
		cout<<ans<<endl;
	}
}

Compilation message

joi2019_ho_t3.cpp:1: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    1 | #pragma optimize("Bismillahirrahmanirrahim")
      | 
joi2019_ho_t3.cpp: In function 'int32_t main()':
joi2019_ho_t3.cpp:63:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |       if (j>r.size() || k>g.size() || (i-j-k)>y.size()) continue;
      |           ~^~~~~~~~~
joi2019_ho_t3.cpp:63:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |       if (j>r.size() || k>g.size() || (i-j-k)>y.size()) continue;
      |                         ~^~~~~~~~~
joi2019_ho_t3.cpp:63:46: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |       if (j>r.size() || k>g.size() || (i-j-k)>y.size()) continue;
      |                                       ~~~~~~~^~~~~~~~~
joi2019_ho_t3.cpp:65:23: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
   65 |       if (j+k+y.size()<i) continue;
      |           ~~~~~~~~~~~~^~
joi2019_ho_t3.cpp:66:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |       if (z==0 && j<r.size() && old[j+1][k][1]!=-1){
      |                   ~^~~~~~~~~
joi2019_ho_t3.cpp:72:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |       if (z==0 && j<r.size() && old[j+1][k][2]!=-1){
      |                   ~^~~~~~~~~
joi2019_ho_t3.cpp:78:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |       if (z==1 && k<g.size() && old[j][k+1][0]!=-1){
      |                   ~^~~~~~~~~
joi2019_ho_t3.cpp:84:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |       if (z==1 && k<g.size() && old[j][k+1][2]!=-1){
      |                   ~^~~~~~~~~
joi2019_ho_t3.cpp:90:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |       if (z==2 && i-j-k<y.size() && old[j][k][0]!=-1){
      |                   ~~~~~^~~~~~~~~
joi2019_ho_t3.cpp:96:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |       if (z==2 && i-j-k<y.size() && old[j][k][1]!=-1){
      |                   ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 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 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 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 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 3 ms 860 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 3 ms 856 KB Output is correct
21 Correct 2 ms 860 KB Output is correct
22 Correct 2 ms 860 KB Output is correct
23 Correct 2 ms 860 KB Output is correct
24 Correct 2 ms 860 KB Output is correct
25 Correct 2 ms 868 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 3 ms 860 KB Output is correct
28 Correct 2 ms 712 KB Output is correct
29 Correct 2 ms 856 KB Output is correct
30 Correct 3 ms 856 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Correct 1 ms 860 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 2 ms 860 KB Output is correct
37 Correct 2 ms 712 KB Output is correct
38 Correct 2 ms 860 KB Output is correct
39 Correct 3 ms 860 KB Output is correct
40 Correct 1 ms 712 KB Output is correct
41 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 295 ms 18108 KB Output is correct
3 Correct 305 ms 18032 KB Output is correct
4 Correct 301 ms 18012 KB Output is correct
5 Correct 288 ms 18108 KB Output is correct
6 Correct 325 ms 18124 KB Output is correct
7 Correct 267 ms 18028 KB Output is correct
8 Correct 314 ms 18028 KB Output is correct
9 Correct 296 ms 17932 KB Output is correct
10 Correct 301 ms 18112 KB Output is correct
11 Correct 295 ms 18112 KB Output is correct
12 Correct 43 ms 4952 KB Output is correct
13 Correct 75 ms 8536 KB Output is correct
14 Correct 133 ms 12492 KB Output is correct
15 Correct 305 ms 18264 KB Output is correct
16 Correct 305 ms 18112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 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 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 3 ms 860 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 3 ms 856 KB Output is correct
21 Correct 2 ms 860 KB Output is correct
22 Correct 2 ms 860 KB Output is correct
23 Correct 2 ms 860 KB Output is correct
24 Correct 2 ms 860 KB Output is correct
25 Correct 2 ms 868 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 3 ms 860 KB Output is correct
28 Correct 2 ms 712 KB Output is correct
29 Correct 2 ms 856 KB Output is correct
30 Correct 3 ms 856 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Correct 1 ms 860 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 2 ms 860 KB Output is correct
37 Correct 2 ms 712 KB Output is correct
38 Correct 2 ms 860 KB Output is correct
39 Correct 3 ms 860 KB Output is correct
40 Correct 1 ms 712 KB Output is correct
41 Correct 1 ms 860 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 295 ms 18108 KB Output is correct
44 Correct 305 ms 18032 KB Output is correct
45 Correct 301 ms 18012 KB Output is correct
46 Correct 288 ms 18108 KB Output is correct
47 Correct 325 ms 18124 KB Output is correct
48 Correct 267 ms 18028 KB Output is correct
49 Correct 314 ms 18028 KB Output is correct
50 Correct 296 ms 17932 KB Output is correct
51 Correct 301 ms 18112 KB Output is correct
52 Correct 295 ms 18112 KB Output is correct
53 Correct 43 ms 4952 KB Output is correct
54 Correct 75 ms 8536 KB Output is correct
55 Correct 133 ms 12492 KB Output is correct
56 Correct 305 ms 18264 KB Output is correct
57 Correct 305 ms 18112 KB Output is correct
58 Correct 488 ms 18108 KB Output is correct
59 Execution timed out 513 ms 18112 KB Time limit exceeded
60 Halted 0 ms 0 KB -