Submission #343894

# Submission time Handle Problem Language Result Execution time Memory
343894 2021-01-04T17:21:53 Z _ani Red-blue table (IZhO19_stones) C++17
11 / 100
46 ms 2156 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
char w[1002][1002];
void Nvnvik(int n, int m, int k) {
	int i = 0, j = 0;
	while (i < m)
	{
		int cnt = 0;
		while (cnt < k)
		{
			w[j][i] = '-';
			j++;
			if (j >= n)
				j = 0;
			cnt++;
		}
		i++;
	}

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (w[i][j] == '.')
				w[i][j] = '+';
}
void Nvnvik2(int n, int m, int k) {
	int i = 0, j = 0;
	while (i < m)
	{
		int cnt = 0;
		while (cnt < k)
		{
			w[i][j] = '+';
			j++;
			if (j >= m)
				j = 0;
			cnt++;
		}
		i++;
	}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (w[i][j] == '.')
				w[i][j] = '-';
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int n, m;
		cin >> n >> m;
		if (min(n, m) <= 2) {
			cout << max(m, n) << '\n';
			char d;
			if (m > n)
				d = '-';
			else d = '+';
			for (int i = 0; i < n; i++)
			{
				for (int j = 0; j < m; j++)
					cout << d;
				cout << '\n';
			}
			continue;
		}
		for (int i = 0; i <= n; i++)
			for (int j = 0; j < m; j++)
				w[i][j] = '.';
		if (n % 2 && m % 2) {
			cout << n + m - 2 << '\n';
			Nvnvik(n - 1, m - 1, n / 2);
			for (int j = 0; j < m; j++)
				w[n - 1][j] = '-';
			for (int i = 0; i < n - 1; i++)
				w[i][m - 1] = '+';
		}
		if (n % 2 == 0 && m % 2 == 1) {
			if (n - m / 2 <= 1) {
				Nvnvik2(n, m - 2, m / 2 - 1);
				for (int i = 0; i < n; i++)
					w[i][m - 1] = w[i][m - 2] = '+';
			}
			else {
				cout << n + m - 2 << '\n';
				Nvnvik(n - 1, m - 2, n / 2);
				for (int j = 0; j < m; j++)
					w[n - 1][j] = '-';
				for (int i = 0; i < n - 1; i++) {
					w[i][m - 1] = ('+');
					w[i][m - 2] = ('+');
				}
			}
		}
		if (n % 2 == 1 && m % 2 == 0) {
			if (m - n / 2 <= 1) {
				Nvnvik(n - 2, m, n / 2 - 1);
				for (int i = 0; i < m; i++)
					w[n - 1][i] = w[n - 2][i] = '-';
			}
			else {
				cout << n + m - 2 << '\n';
				Nvnvik(n - 2, m - 1, n / 2 - 1);
				for (int j = 0; j < m; j++) {
					w[n - 2][j] = '-';
					w[n - 1][j] = '-';
				}
				for (int i = 0; i < n - 2; i++)
					w[i][m - 1] = '+';
			}
		}
		if (n % 2 == 0 && m % 2 == 0) {
			cout << n + m - 3 << '\n';
			Nvnvik(n - 3, m, n / 2 - 2);
			for (int i = 0; i < m; i++)
				w[n - 1][i] = w[n - 2][i] = w[n - 3][i] = '-';
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++)
				cout << w[i][j];
			cout << '\n';
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB in the table A+B is not equal to 5
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 364 KB in the table A+B is not equal to 5
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB in the table A+B is not equal to 5
# Verdict Execution time Memory Grader output
1 Correct 46 ms 1388 KB Output is correct
2 Correct 39 ms 2028 KB Output is correct
3 Correct 40 ms 2156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 1516 KB in the table A+B is not equal to 45
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB in the table A+B is not equal to 5