# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1107407 | vjudge1 | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++17 | 1 ms | 552 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
using namespace std;
const int N=2e5+5;
const int inf=1e9;
const int mod=1e9+7;
const int N1=1e6+1;
vector<int>v;
vector<int>v1;
struct edge{
int v,time;
};
int dp[1001];
signed main(){
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n;
cin>>n;
string s;
cin>>s;
int cnt=0;
int cnt1=0;
for(int i=1;i<=n;i++){
if(s[i-1]=='R'){
cnt++;
}else{
cnt1++;
}
}
if(n%2==0&&abs(cnt-cnt1)!=0||n%2==1&&abs(cnt-cnt1)!=1){
cout<<"-1";
return 0;
}
int j=2;
int l=1;
int ans1=0;
int ans2=0;
for(int i=1;i<=n;i++){
if(s[i-1]=='R'){
ans1+=abs(j-i);
ans2+=abs(l-i);
l+=2;
j+=2;
}
}
int cnt3=(n+1)/2;
if(cnt!=cnt3){
ans2=inf;
}
int cnt4=n/2;
if(cnt4!=cnt){
ans1=inf;
}
cout<<min(ans1,ans2);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |