답안 #343923

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
343923 2021-01-04T18:29:27 Z _ani Red-blue table (IZhO19_stones) C++17
53 / 100
49 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 (m - 1 - n / 2 <= 1) {
				cout << n + m - 2 << '\n';
				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 - 3 << '\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 (n - 1 - m / 2 <= 1) {
				cout << n + m - 2 << '\n';
				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 - 3 << '\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) {
			if (n - 3 <= m / 2) {
				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] = '-';
			}
			else if (m - 3 <= n / 2) {
				cout << n + m - 3 << '\n';
				Nvnvik2(n, m - 3, m / 2 - 2);
				for (int i = 0; i < n; i++)
					w[i][m - 1] = w[i][m - 2] = w[i][m - 3] = '+';
			}
			else {
				cout << n + m - 4 << '\n';
				Nvnvik(n - 2, m - 2, n / 2 - 1);
				for (int i = 0; i < m; i++)
					w[n - 1][i] = w[n - 2][i] = '-';
				for (int i = 0; i < n - 2; i++)
					w[i][m - 1] = w[i][m - 2] = '+';
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++)
				cout << w[i][j];
			cout << '\n';
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 380 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Incorrect 4 ms 364 KB in the table A+B is not equal to 26
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 1440 KB Output is correct
2 Correct 40 ms 2028 KB Output is correct
3 Correct 38 ms 2156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 1536 KB Output is correct
2 Correct 37 ms 1900 KB Output is correct
3 Correct 33 ms 1644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 380 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Incorrect 4 ms 364 KB in the table A+B is not equal to 26