#include <bits/stdc++.h>
using namespace std;
#define int long long
#define OYY 100000005
#define mod 998244353
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mid (start+end)/2
#define lim 65
#define fi first
#define se second
int n;// 1 2 3
vector<int> v[4];
int dp[lim][lim][lim][4];
int gec[4][lim][4][lim];// renk index diğer index
inline int dpp(int red,int gre,int yel,int sira,int renk){
if(sira>=n){
return 0;
}
if(~dp[red][gre][yel][renk])return dp[red][gre][yel][renk];
int yum=OYY;
if(renk!=1 && red<v[1].size()){
int deg=0,deg2=0;
if(gre>0)deg=gec[1][red][2][gre-1];
if(yel>0)deg2=gec[1][red][3][yel-1];
yum=min(yum,dpp(red+1,gre,yel,sira+1,1)+v[1][red]+deg+deg2-sira);
}
if(renk!=2 && gre<v[2].size()){
int deg=0,deg2=0;
if(red>0)deg=gec[2][gre][1][red-1];
if(yel>0)deg2=gec[2][gre][3][yel-1];
yum=min(yum,dpp(red,gre+1,yel,sira+1,2)+v[2][gre]+deg+deg2-sira);
}
if(renk!=3 && yel<v[3].size()){
int deg=0,deg2=0;
if(red>0)deg=gec[3][yel][1][red-1];
if(gre>0)deg2=gec[3][yel][2][gre-1];
yum=min(yum,dpp(red,gre,yel+1,sira+1,3)+v[3][yel]+deg+deg2-sira);
}
return dp[red][gre][yel][renk]=yum;
}
int32_t main(){
faster
memset(dp,-1,sizeof(dp));
cin>>n;
string s;cin>>s;
for(int i=0;i<n;i++){
if(s[i]=='R')v[1].push_back(i);
else if(s[i]=='G')v[2].push_back(i);
else v[3].push_back(i);
}
for(int i=0;i<v[1].size();i++){
int tut=0;
for(int j=0;j<v[2].size();j++){
if(v[1][i]<v[2][j])tut++;
gec[1][i][2][j]=tut;
}
}
for(int i=0;i<v[1].size();i++){
int tut=0;
for(int j=0;j<v[3].size();j++){
if(v[1][i]<v[3][j])tut++;
gec[1][i][3][j]=tut;
}
}
for(int i=0;i<v[2].size();i++){
int tut=0;
for(int j=0;j<v[1].size();j++){
if(v[2][i]<v[1][j])tut++;
gec[2][i][1][j]=tut;
}
}
for(int i=0;i<v[2].size();i++){
int tut=0;
for(int j=0;j<v[3].size();j++){
if(v[2][i]<v[3][j])tut++;
gec[2][i][3][j]=tut;
}
}
for(int i=0;i<v[3].size();i++){
int tut=0;
for(int j=0;j<v[1].size();j++){
if(v[3][i]<v[1][j])tut++;
gec[3][i][1][j]=tut;
}
}
for(int i=0;i<v[3].size();i++){
int tut=0;
for(int j=0;j<v[2].size();j++){
if(v[3][i]<v[2][j])tut++;
gec[3][i][2][j]=tut;
}
}
string h="";
int deg=dpp(0,0,0,0,0);
if(deg==OYY)deg=-1;
cout<<deg<<'\n';
return 0;
}
Compilation message
joi2019_ho_t3.cpp: In function 'long long int dpp(long long int, long long int, long long int, long long int, long long int)':
joi2019_ho_t3.cpp:22:19: 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]
22 | if(renk!=1 && red<v[1].size()){
| ~~~^~~~~~~~~~~~
joi2019_ho_t3.cpp:28:19: 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]
28 | if(renk!=2 && gre<v[2].size()){
| ~~~^~~~~~~~~~~~
joi2019_ho_t3.cpp:34:19: 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]
34 | if(renk!=3 && yel<v[3].size()){
| ~~~^~~~~~~~~~~~
joi2019_ho_t3.cpp: In function 'int32_t main()':
joi2019_ho_t3.cpp:53:15: 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]
53 | for(int i=0;i<v[1].size();i++){
| ~^~~~~~~~~~~~
joi2019_ho_t3.cpp:55:16: 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]
55 | for(int j=0;j<v[2].size();j++){
| ~^~~~~~~~~~~~
joi2019_ho_t3.cpp:60:15: 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]
60 | for(int i=0;i<v[1].size();i++){
| ~^~~~~~~~~~~~
joi2019_ho_t3.cpp:62:16: 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]
62 | for(int j=0;j<v[3].size();j++){
| ~^~~~~~~~~~~~
joi2019_ho_t3.cpp:67:15: 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]
67 | for(int i=0;i<v[2].size();i++){
| ~^~~~~~~~~~~~
joi2019_ho_t3.cpp:69:16: 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]
69 | for(int j=0;j<v[1].size();j++){
| ~^~~~~~~~~~~~
joi2019_ho_t3.cpp:74:15: 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]
74 | for(int i=0;i<v[2].size();i++){
| ~^~~~~~~~~~~~
joi2019_ho_t3.cpp:76:16: 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]
76 | for(int j=0;j<v[3].size();j++){
| ~^~~~~~~~~~~~
joi2019_ho_t3.cpp:81:15: 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]
81 | for(int i=0;i<v[3].size();i++){
| ~^~~~~~~~~~~~
joi2019_ho_t3.cpp:83:16: 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]
83 | for(int j=0;j<v[1].size();j++){
| ~^~~~~~~~~~~~
joi2019_ho_t3.cpp:88:15: 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]
88 | for(int i=0;i<v[3].size();i++){
| ~^~~~~~~~~~~~
joi2019_ho_t3.cpp:90:16: 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 | for(int j=0;j<v[2].size();j++){
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
9308 KB |
Output is correct |
2 |
Correct |
2 ms |
9308 KB |
Output is correct |
3 |
Correct |
2 ms |
9308 KB |
Output is correct |
4 |
Correct |
2 ms |
9308 KB |
Output is correct |
5 |
Correct |
2 ms |
9416 KB |
Output is correct |
6 |
Correct |
2 ms |
9308 KB |
Output is correct |
7 |
Correct |
2 ms |
9308 KB |
Output is correct |
8 |
Correct |
2 ms |
9308 KB |
Output is correct |
9 |
Correct |
2 ms |
9308 KB |
Output is correct |
10 |
Correct |
2 ms |
9308 KB |
Output is correct |
11 |
Correct |
2 ms |
9308 KB |
Output is correct |
12 |
Correct |
2 ms |
9304 KB |
Output is correct |
13 |
Correct |
2 ms |
9308 KB |
Output is correct |
14 |
Correct |
2 ms |
9308 KB |
Output is correct |
15 |
Correct |
2 ms |
9308 KB |
Output is correct |
16 |
Correct |
2 ms |
9308 KB |
Output is correct |
17 |
Correct |
2 ms |
9308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
9308 KB |
Output is correct |
2 |
Correct |
2 ms |
9308 KB |
Output is correct |
3 |
Correct |
2 ms |
9308 KB |
Output is correct |
4 |
Correct |
2 ms |
9308 KB |
Output is correct |
5 |
Correct |
2 ms |
9416 KB |
Output is correct |
6 |
Correct |
2 ms |
9308 KB |
Output is correct |
7 |
Correct |
2 ms |
9308 KB |
Output is correct |
8 |
Correct |
2 ms |
9308 KB |
Output is correct |
9 |
Correct |
2 ms |
9308 KB |
Output is correct |
10 |
Correct |
2 ms |
9308 KB |
Output is correct |
11 |
Correct |
2 ms |
9308 KB |
Output is correct |
12 |
Correct |
2 ms |
9304 KB |
Output is correct |
13 |
Correct |
2 ms |
9308 KB |
Output is correct |
14 |
Correct |
2 ms |
9308 KB |
Output is correct |
15 |
Correct |
2 ms |
9308 KB |
Output is correct |
16 |
Correct |
2 ms |
9308 KB |
Output is correct |
17 |
Correct |
2 ms |
9308 KB |
Output is correct |
18 |
Correct |
2 ms |
9308 KB |
Output is correct |
19 |
Correct |
2 ms |
9444 KB |
Output is correct |
20 |
Correct |
2 ms |
9308 KB |
Output is correct |
21 |
Correct |
2 ms |
9308 KB |
Output is correct |
22 |
Correct |
2 ms |
9304 KB |
Output is correct |
23 |
Correct |
2 ms |
9420 KB |
Output is correct |
24 |
Correct |
2 ms |
9304 KB |
Output is correct |
25 |
Correct |
2 ms |
9308 KB |
Output is correct |
26 |
Correct |
2 ms |
9308 KB |
Output is correct |
27 |
Correct |
2 ms |
9308 KB |
Output is correct |
28 |
Correct |
2 ms |
9428 KB |
Output is correct |
29 |
Correct |
2 ms |
9308 KB |
Output is correct |
30 |
Correct |
2 ms |
9308 KB |
Output is correct |
31 |
Correct |
2 ms |
9308 KB |
Output is correct |
32 |
Correct |
2 ms |
9308 KB |
Output is correct |
33 |
Correct |
2 ms |
9308 KB |
Output is correct |
34 |
Correct |
2 ms |
9308 KB |
Output is correct |
35 |
Correct |
2 ms |
9308 KB |
Output is correct |
36 |
Correct |
2 ms |
9308 KB |
Output is correct |
37 |
Correct |
2 ms |
9564 KB |
Output is correct |
38 |
Correct |
2 ms |
9308 KB |
Output is correct |
39 |
Correct |
2 ms |
9308 KB |
Output is correct |
40 |
Correct |
3 ms |
9308 KB |
Output is correct |
41 |
Correct |
2 ms |
9308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
9308 KB |
Output is correct |
2 |
Incorrect |
2 ms |
9308 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
9308 KB |
Output is correct |
2 |
Correct |
2 ms |
9308 KB |
Output is correct |
3 |
Correct |
2 ms |
9308 KB |
Output is correct |
4 |
Correct |
2 ms |
9308 KB |
Output is correct |
5 |
Correct |
2 ms |
9416 KB |
Output is correct |
6 |
Correct |
2 ms |
9308 KB |
Output is correct |
7 |
Correct |
2 ms |
9308 KB |
Output is correct |
8 |
Correct |
2 ms |
9308 KB |
Output is correct |
9 |
Correct |
2 ms |
9308 KB |
Output is correct |
10 |
Correct |
2 ms |
9308 KB |
Output is correct |
11 |
Correct |
2 ms |
9308 KB |
Output is correct |
12 |
Correct |
2 ms |
9304 KB |
Output is correct |
13 |
Correct |
2 ms |
9308 KB |
Output is correct |
14 |
Correct |
2 ms |
9308 KB |
Output is correct |
15 |
Correct |
2 ms |
9308 KB |
Output is correct |
16 |
Correct |
2 ms |
9308 KB |
Output is correct |
17 |
Correct |
2 ms |
9308 KB |
Output is correct |
18 |
Correct |
2 ms |
9308 KB |
Output is correct |
19 |
Correct |
2 ms |
9444 KB |
Output is correct |
20 |
Correct |
2 ms |
9308 KB |
Output is correct |
21 |
Correct |
2 ms |
9308 KB |
Output is correct |
22 |
Correct |
2 ms |
9304 KB |
Output is correct |
23 |
Correct |
2 ms |
9420 KB |
Output is correct |
24 |
Correct |
2 ms |
9304 KB |
Output is correct |
25 |
Correct |
2 ms |
9308 KB |
Output is correct |
26 |
Correct |
2 ms |
9308 KB |
Output is correct |
27 |
Correct |
2 ms |
9308 KB |
Output is correct |
28 |
Correct |
2 ms |
9428 KB |
Output is correct |
29 |
Correct |
2 ms |
9308 KB |
Output is correct |
30 |
Correct |
2 ms |
9308 KB |
Output is correct |
31 |
Correct |
2 ms |
9308 KB |
Output is correct |
32 |
Correct |
2 ms |
9308 KB |
Output is correct |
33 |
Correct |
2 ms |
9308 KB |
Output is correct |
34 |
Correct |
2 ms |
9308 KB |
Output is correct |
35 |
Correct |
2 ms |
9308 KB |
Output is correct |
36 |
Correct |
2 ms |
9308 KB |
Output is correct |
37 |
Correct |
2 ms |
9564 KB |
Output is correct |
38 |
Correct |
2 ms |
9308 KB |
Output is correct |
39 |
Correct |
2 ms |
9308 KB |
Output is correct |
40 |
Correct |
3 ms |
9308 KB |
Output is correct |
41 |
Correct |
2 ms |
9308 KB |
Output is correct |
42 |
Correct |
2 ms |
9308 KB |
Output is correct |
43 |
Incorrect |
2 ms |
9308 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |