Submission #526601

# Submission time Handle Problem Language Result Execution time Memory
526601 2022-02-15T14:11:14 Z Zhora_004 Red-blue table (IZhO19_stones) C++17
27 / 100
66 ms 336 KB
#include <iostream>
#include <vector>

using namespace std;

bool t1(int n, int m)
{
	return max(n, m) <= 4;
}

bool t2(int n, int m)
{
	return min(n, m) <= 3;
}

void test_case()
{
	int n, m;
	cin >> n >> m;
	if (t1(n, m))
	{
		int mx = 0;
		vector<vector<bool>> ans;
		int k = n * m;
		for (int i = 0; i < (1 << k); i++)
		{
			vector<vector<bool>> v(n, vector<bool>(m));
			for (int j = 0; j < k; j++)
			{
				if ((i >> j) & 1)
				{
					int r = j / m, c = j % m;
					v[r][c] = 1;
				}
			}
			int A = 0, B = 0;
			for (int j = 0; j < n; j++)
			{
				int a = 0, b = 0;
				for (int k = 0; k < m; k++)
				{
					if (v[j][k]) a++;
					else b++;
				}
				if (a > b) A++;
			}
			for (int j = 0; j < m; j++)
			{
				int a = 0, b = 0;
				for (int k = 0; k < n; k++)
				{
					if (v[k][j]) a++;
					else b++;
				}
				if (b > a) B++;
			}
			if (A + B > mx) ans = v, mx = A + B;
		}
		cout << mx << "\n";
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				if (ans[i][j]) cout << '+';
				else cout << '-';
			}
			cout << "\n";
		}
		return;
	}
	if (t2(n, m))
	{
		if (m >= n)
		{
			if (n <= 2) cout << m << "\n";
			else cout << m + 1 << "\n";
			for (int i = 0; i < n; i++)
			{
				for (int j = 0; j < m; j++)
				{
					if (i < (n - 1) / 2) cout << '+';
					else cout << '-';
				}
				cout << "\n";
			}
		}
		else
		{
			if (m <= 2) cout << n << "\n";
			else cout << n + 1 << "\n";
			for (int i = 0; i < n; i++)
			{
				for (int j = 0; j < m - 1; j++) cout << '+';
				if (m <= 2) cout << "+\n";
				else cout << "-\n";
			}
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tc;
	cin >> tc;
	while (tc--)
		test_case();

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 27 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 27 ms 308 KB Output is correct
3 Correct 4 ms 332 KB Output is correct
4 Incorrect 66 ms 336 KB Wrong answer
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 208 KB Wrong answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 204 KB Wrong answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 27 ms 308 KB Output is correct
3 Correct 4 ms 332 KB Output is correct
4 Incorrect 66 ms 336 KB Wrong answer
5 Halted 0 ms 0 KB -