#include <bits/stdc++.h>
using namespace std;
#define accepted ios_base::sync_with_stdio(0);cin.tie(0);
#define Daulbekov signed
#define Makan main
#define int long long
#define double long double
#define pb push_back
#define F first
#define S second
const long long N=5e5+10;
const long long MOD=1e9+7;
const long long INF=2e18;
int binpow(int a,int b){
a%=MOD;
if(b==0)return 1;
if(b%2)return binpow(a,b-1)*a%MOD;
else {
int res=binpow(a,b/2);
return res*res%MOD;
}
}
bool cmp(pair<int,int>a,pair<int,int>b){
if(a.F/300!=b.F/300)return a.F/300<b.F/300;
return a.S<b.S;
}
int g,r;
Daulbekov Makan(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
accepted
int n;
cin>>n;
string s;
cin>>s;
for(int i=0;i<n;i++){
if(s[i]=='G')g++;
else r++;
}
if(r!=n/2&&g!=n/2){
cout<<-1;
return 0;
}
if(n%2==0){
int cnt=0,ans,cur=0,cur1=1;
for(int i=0;i<n;i++){
if(s[i]=='R'){
cnt+=abs(cur-i);
cur+=2;
}
else{
cnt+=abs(cur1-i);
cur1+=2;
}
}
ans=cnt;
cnt=0,cur=1,cur1=0;
for(int i=0;i<n;i++){
if(s[i]=='R'){
cnt+=abs(cur-i);
cur+=2;
}
else{
cnt+=abs(cur1-i);
cur1+=2;
}
}
cout<<min(ans,cnt)/2;
return 0;
}
if(r==n/2){
int cnt=0,cur=0,cur1=1;
for(int i=0;i<n;i++){
if(s[i]=='R'){
cnt+=abs(cur1-i);
cur1+=2;
}
else{
cnt+=abs(cur-i);
cur+=2;
}
}
cout<<cnt/2;
}
else{
int cnt=0,cur=1,cur1=0;
for(int i=0;i<n;i++){
if(s[i]=='R'){
cnt+=abs(cur1-i);
cur1+=2;
}
else{
cnt+=abs(cur-i);
cur+=2;
}
}
cout<<cnt/2;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
456 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |