Submission #586435

# Submission time Handle Problem Language Result Execution time Memory
586435 2022-06-30T09:06:49 Z blue Red-blue table (IZhO19_stones) C++17
100 / 100
23 ms 2352 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;

vi ct;

int main()
{
	int T;
	cin >> T;

	for(int t = 1; t <= T; t++)
	{
		int N, M;
		cin >> N >> M;

		int A = 0, B = 0;

		// cerr << "1\n";

		if(N > M)
		{
			A = N;
		}
		else
			B = M;

		for(int a = 1; a <= N; a++)
		{
			for(int b = 1; b <= M; b++)
			{
				int redperrow = M/2 + 1;
				int lostcols = M - b;

				int remred = max(0, redperrow - lostcols);

				int totalred = remred * a;

				int z = totalred/b + bool(totalred % b);

				// cerr << a << ' ' << b << " : " << redperrow << ' ' << lostcols << "\n";

				if(z < N - z)
				{
					if(a+b > A+B)
					{
						A = a;
						B = b;
					}
				}
			}
		}
		// cerr << "2\n";

		// cout << A << ' ' << B << '\n';

		cout << A+B << '\n';

		vector<string> res(N, string(M, '-'));

		int redperrow = M/2 + 1;

		ct = vi(M, 0);

		for(int a = 0; a < A; a++)
		{
			for(int x = 0; x < min(M - B, redperrow); x++)
			{
				res[a][x] = '+';
			}

			int rem = redperrow - min(M - B, redperrow);

			vi I;
			for(int j = M - B; j < M; j++)
				I.push_back(j);

			sort(I.begin(), I.end(), [] (int u, int v)
			{
				return ct[u] < ct[v];
			});

			for(int q = 0; q < rem; q++)
			{
				ct[I[q]]++;
				res[a][I[q]] = '+';
			}
		}

		for(int i = 0; i < N; i++)
			cout << res[i] << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 1300 KB Output is correct
2 Correct 18 ms 1752 KB Output is correct
3 Correct 21 ms 1836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1308 KB Output is correct
2 Correct 17 ms 1476 KB Output is correct
3 Correct 15 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 23 ms 1300 KB Output is correct
6 Correct 18 ms 1752 KB Output is correct
7 Correct 21 ms 1836 KB Output is correct
8 Correct 21 ms 1308 KB Output is correct
9 Correct 17 ms 1476 KB Output is correct
10 Correct 15 ms 1388 KB Output is correct
11 Correct 8 ms 468 KB Output is correct
12 Correct 15 ms 1492 KB Output is correct
13 Correct 17 ms 1460 KB Output is correct
14 Correct 13 ms 1052 KB Output is correct
15 Correct 20 ms 2352 KB Output is correct
16 Correct 16 ms 1720 KB Output is correct
17 Correct 7 ms 980 KB Output is correct