#include <bits/stdc++.h>
using namespace std;
signed main(){
int n; cin >> n;
string s; cin >> s;
map<char, vector<int>> pos;
for(int i = 0; i < n; i++)
pos[s[i]].push_back(i);
auto check = [&](string t) -> int{
int res = 0;
map<char, int> ind;
ind['R']=0, ind['G']=0, ind['Y']=0;
for(int i = 0; i < n; i++){
if(i < n-1) if(t[i] == t[i+1]) return 1e9;
res += abs(i-pos[t[i]][ind[t[i]]++]);
}
return res;
};
int ans = 1e9;
sort(begin(s), end(s));
ans = min(ans, check(s));
while(next_permutation(begin(s), end(s))){
ans = min(ans, check(s));
//cout << s << " " << ans << endl;
}
cout << (ans == 1e9 ? -1 : ans/2) << endl;
}
# |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
42 ms |
348 KB |
Output is correct |
6 |
Correct |
73 ms |
348 KB |
Output is correct |
7 |
Correct |
55 ms |
600 KB |
Output is correct |
8 |
Correct |
73 ms |
344 KB |
Output is correct |
9 |
Correct |
6 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Incorrect |
42 ms |
348 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
42 ms |
348 KB |
Output is correct |
6 |
Correct |
73 ms |
348 KB |
Output is correct |
7 |
Correct |
55 ms |
600 KB |
Output is correct |
8 |
Correct |
73 ms |
344 KB |
Output is correct |
9 |
Correct |
6 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Incorrect |
42 ms |
348 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1064 ms |
348 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
42 ms |
348 KB |
Output is correct |
6 |
Correct |
73 ms |
348 KB |
Output is correct |
7 |
Correct |
55 ms |
600 KB |
Output is correct |
8 |
Correct |
73 ms |
344 KB |
Output is correct |
9 |
Correct |
6 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Incorrect |
42 ms |
348 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |