Submission #202987

#TimeUsernameProblemLanguageResultExecution timeMemory
202987luciocfRed-blue table (IZhO19_stones)C++14
15 / 100
77 ms1912 KiB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e3+10;

struct S
{
	int ind, qtd;
} col[maxn];

char tab[maxn][maxn];

bool comp(S a, S b) {return a.qtd > b.qtd;}

int main(void)
{
	int t;
	scanf("%d", &t);

	while (t--)
	{
		int n, m;
		scanf("%d %d", &n, &m);

		for (int i = 1; i <= m; i++)
			col[i] = {i, n};

		int mx = m, opt = 0;
		int tot = m;

		for (int A = 1; A <= n; A++)
		{
			sort(col+1, col+m+1, comp);

			for (int i = 1, cnt = 0; i <= m && cnt < (m+2)/2; i++)
			{
				if (col[i].qtd != 0)
				{
					cnt++;
					col[i].qtd--;

					if (col[i].qtd < (n+2)/2) tot--;
				}
			}

			if (A+tot > mx)
			{
				mx = A+tot;
				opt = A;
			}
		}

		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m; j++)
				tab[i][j] = '-';

		for (int i = 1; i <= m; i++)
			col[i] = {i, n};

		for (int A = 1; A <= opt; A++)
		{
			sort(col+1, col+m+1, comp);

			for (int i = 1, cnt = 0; i <= m && cnt < (m+2)/2; i++)
			{
				if (col[i].qtd != 0)
				{
					cnt++;
					col[i].qtd--;

					tab[A][col[i].ind] = '+';
				}
			}
		}

		printf("%d\n", mx);
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= m; j++)
				printf("%c", tab[i][j]);
			printf("\n");
		}
	}
}

Compilation message (stderr)

stones.cpp: In function 'int main()':
stones.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &t);
  ~~~~~^~~~~~~~~~
stones.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &m);
   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...