#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin >> n;
vector<char> C(n);
ll r = 0, y = 0, g = 0, mx = (n + 1) / 2;
for (int i = 0; i < n; i++)
{
cin >> C[i];
if (C[i] == 'R')
{
r++;
}
else if (C[i] == 'Y')
{
y++;
}
else
{
g++;
}
}
if (r > mx || y > mx || g > mx)
{
cout << -1;
}
else
{
// SUBTASK 3
// RGRGRG atau GRGRGR
ll pos1 = 0, pos2 = 1;
ll ans1 = 0, ans2 = 0;
for (int i = 0; i < n; i++)
{
if (C[i] == 'B')
{
ans1 += abs(i - pos1);
ans2 += abs(i - pos2);
pos1 += 2;
pos2 += 2;
}
}
cout << min(ans1, ans2);
return 0;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |