# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
883021 | vjudge1 | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++11 | 1 ms | 756 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 pb push_back
#define endl ("\n")
#define all(aa) aa.begin(), aa.end()
typedef long long ll;
using namespace std;
int solve(int target, vector<int> v){
int ret = 0;
for(int i = 0; i < v.size(); i++){
target ^=1;
if(v[i] == target) continue;
int j;
for(j = 1; i+j < v.size(); j++){
if(v[i+j] == target){
v[i+j]^=1;
break;
}
}
ret+=j;
}
return ret;
}
int main(){
int n, cnt = 0;
cin >> n;
vector<int> v(n);
for(int i = 0; i < n; i++){
char c; cin >> c;
v[i] = (c=='R');
cnt += v[i];
}
if(cnt > (n+1)/2 || (n-cnt) > (n+1)/2){
cout << -1;
exit(0);
}
if(n > 2*cnt){
for(int i = 0; i < n; i++) v[i] ^=1;
cnt = n - cnt;
}
int ans = solve(0, v);
if(!(n&1)) ans = min(ans, solve(1, v));
cout << ans << endl;
}
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... |