Submission #110440

# Submission time Handle Problem Language Result Execution time Memory
110440 2019-05-10T20:54:43 Z luciocf Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
0 / 100
3 ms 384 KB
#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

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
joi2019_ho_t3.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c", &a[i]);
   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -