Submission #110417

# Submission time Handle Problem Language Result Execution time Memory
110417 2019-05-10T19:40:00 Z sofhiasouza Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
0 / 100
3 ms 384 KB
#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

joi2019_ho_t3.cpp: In function 'int func(char, char)':
joi2019_ho_t3.cpp:11:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1 ; i < s.size() ; i++)
                  ~~^~~~~~~~~~
joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:40:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0 ; i < s.size() ; i++)
                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Incorrect 3 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Incorrect 3 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Incorrect 3 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -