# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
110417 | sofhiasouza | 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;
int n, cont;
string s;
inline int func(char x, char y)
{
queue < int > fila;
if(s[0] != x) fila.push(0);
for(int i = 1 ; i < s.size() ; i++)
{
if(s[i] == x and fila.size())
{
cont += i - fila.front();
fila.pop();
s[i] = y;
s[i-1] = x;
}
if(s[i] == s[i-1])
{
if(x == s[i])
{
fila.push(i);
char aux = x;
x = y;
y = aux;
}
else fila.push(i);
}
}
return cont;
}
int main()
{
cin >> n;
cin >> s;
int r = 0, g = 0;
for(int i = 0 ; i < s.size() ; i++)
{
if(s[i] == 'R') r++;
else g++;
}
if(r > g+1 or g > r+1) cout << -1 << endl;
else
{
if(r > g) cout << func('R', 'G') << endl;
else if(g > r) cout << func('G', 'R') << endl;
else cout << func(s[0], s[0] == 'G' ? 'R' : 'G') << 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... |