# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
110440 | luciocf | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++14 | 3 ms | 384 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>
using namespace std;
const int maxn = 410;
char a[maxn], b[maxn];
int main(void)
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf(" %c", &a[i]);
b[i] = a[i];
}
int ans = 0, Ans = 1e9+10;
bool ok = 1;
for (int i = 0; i < n; i++)
{
if ( (i%2 == 0 && b[i] == 'G') || (i%2 == 1 && b[i] == 'R'))
{
ok = 0;
break;
}
bool found = 0;
for (int j = i+1; j < n; j++)
{
if (i%2 == 0 && j%2 == 1 && b[j] == 'G')
{
found = 1;
ans += (j-i);
swap(b[i], b[j]);
break;
}
else if (i%2 == 1 && j%2 == 0 && b[j] == 'R')
{
found = 1;
ans += j-i;
swap(b[i], b[j]);
break;
}
}
if (!found)
{
ok = 0;
break;
}
}
if (ok)
Ans = max(Ans, ans);
ok = 1, ans = 0;
for (int i = 0; i < n; i++)
b[i] = a[i];
for (int i = 0; i < n; i++)
{
if ( (i%2 == 0 && b[i] == 'R') || (i%2 == 1 && b[i] == 'G'))
{
ok = 0;
break;
}
bool found = 0;
for (int j = i+1; j < n; j++)
{
if (i%2 == 0 && j%2 == 1 && b[j] == 'R')
{
found = 1;
ans += j-i;
swap(b[i], b[j]);
break;
}
else if (i%2 == 1 && j%2 == 0 && b[j] == 'G')
{
found = 1;
ans += j-i;
swap(b[i], b[j]);
break;
}
}
if (!found)
{
ok = 0;
break;
}
}
if (ok)
Ans = max(ans, Ans);
if (Ans == 1e9+10)
printf("-1\n");
else
printf("%d\n", Ans);
}
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... |