Submission #963377

# Submission time Handle Problem Language Result Execution time Memory
963377 2024-04-14T22:25:44 Z Saul0906 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
#define ll long long
#define rep(a,b,c) for(ll a=b; a<c; a++)

using namespace std;

int main(){
	ll n;
	string s, s2;
	cin>>n>>s;
	ll a[3]={n-1,n-1,n-1}, ans=1e9, sum;
	rep(i,0,n){
		if(s[i]=='R') a[0]=min(a[0],i);
		if(s[i]=='G') a[1]=min(a[1],i);
		if(s[i]=='Y') a[2]=min(a[2],i);
	}
	s2=s;
	rep(k,0,3){
		sum=0;
		sum+=a[k];
		s=s2;
		swap(s[0],s[a[k]]);
		rep(i,0,n){
			if(i && s[i]==s[i-1]){
				rep(j,i,n){
					if(s[i]!=s[j]){
						swap(s[i],s[j]);
						sum+=j-i;
						break;
					}
				}
				if(s[i]==s[i-1]) sum=1e9;
			}
		}
		ans=min(ans,sum);
	}
	cout<<s<<endl;
	if(ans<1e9)cout<<ans<<endl;
	else cout<<-1<<endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -