| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 497387 | Mukhitali | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++17 | 1 ms | 316 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.
//bit chass 1
#include <bits/stdc++.h>
#define x first
#define y second
#define el "\n"
#define ll long long
#define pb push_back
#define pll pair <ll, ll>
#define pii pair <int, int>
#define all(x) x.begin(), x.end()
#define lcm(x,y) x * y / __gcd(x, y)
#define ibase ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
const int N = 1e5 + 5, inf = 1e9 + 7, M = 2e6, MM = 2e6 + 5, K = 300;
const ll MI = 2e18;
const double P = 3.14;
void solve() {
int n, k = 0;
string s;
cin >> n >> s;
for (int i = 0; i < n; i++)
if (s[i] == 'R')
k++;
if (k > (n + 1) / 2 || (n - k) > (n + 1) / 2)
cout << -1;
else {
int r = 2;
ll ans = 0;
if (n % 2 == 0) {
for (int i = 1; i < s.size(); i++) {
r = max(r, i + 1);
if (s[i] == s[i - 1]) {
while (s[r] == s[i - 1])
r++;
s.erase(r, 1);
ans += r - i;
}
}
}
else {
if (k == n / 2 + 1) {
r = 0;
while (s[r] != 'R')
r++;
ans += r;
for (int i = 1; i < s.size(); i++) {
r = max(r, i + 1);
if (s[i] == s[i - 1]) {
while (s[r] == s[i])
r++;
s.erase(r, 1);
ans += r - i;
}
}
}
else {
}
}
cout << ans;
}
}
int main() {
ibase;
int T = 1;
// cin >> T;
for (int i = 1; i <= T; i++) {
// cout << "Case " << i << ": ";
solve();
cout << el;
}
}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... | ||||
