Submission #384169

# Submission time Handle Problem Language Result Execution time Memory
384169 2021-03-31T15:58:58 Z patrikpavic2 Red-blue table (IZhO19_stones) C++17
100 / 100
53 ms 5484 KB
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 1e3 + 50;

bool jako_dobar(int r, int s, int x, int y){
	x = max(x, 0), y = max(y, 0);
	if(x > s || y > r) return 0;
	if(!s || !r) return 1;
	return (r * x + s - 1) / s <= r - y;
}

bool dobar(int n, int m, int a, int b){
	return jako_dobar(a, b, (m + 2) / 2 - (m - b), (n + 2) / 2 - (n - a));
}

int A[N][N];

void construct(int n, int m, int a, int b){
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++)
			A[i][j] = (j >= b);
	}
	int r = a, s = b, x = (m + 2) / 2 - (m - b);
	int cur = 0;
	for(int i = 0;i < r;i++){
		for(int j = 0;j < x;j++){
			A[i][cur] = 1;
			cur = (cur + 1) % s;
		}
	}
	printf("%d\n", a + b);
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++)
			printf(A[i][j] ? "+" : "-");
		printf("\n");
	}
}

int main(){
	int T; scanf("%d", &T);
	for(;T--;){
		int n, m; scanf("%d%d", &n, &m);
		int A = 0, B = 0;
		for(int a = 0;a <= n;a++)
			for(int b = 0;b <= m;b++)
				if(a + b > A + B && dobar(n, m, a, b))
					A = a, B = b;
		construct(n, m, A, B);
	}
	return 0;
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   43 |  int T; scanf("%d", &T);
      |         ~~~~~^~~~~~~~~~
stones.cpp:45:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |   int n, m; scanf("%d%d", &n, &m);
      |             ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 3 ms 492 KB Output is correct
4 Correct 4 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 1684 KB Output is correct
2 Correct 42 ms 4332 KB Output is correct
3 Correct 53 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 1900 KB Output is correct
2 Correct 39 ms 4076 KB Output is correct
3 Correct 35 ms 3436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 3 ms 492 KB Output is correct
4 Correct 4 ms 492 KB Output is correct
5 Correct 48 ms 1684 KB Output is correct
6 Correct 42 ms 4332 KB Output is correct
7 Correct 53 ms 5100 KB Output is correct
8 Correct 46 ms 1900 KB Output is correct
9 Correct 39 ms 4076 KB Output is correct
10 Correct 35 ms 3436 KB Output is correct
11 Correct 12 ms 680 KB Output is correct
12 Correct 37 ms 4332 KB Output is correct
13 Correct 40 ms 5060 KB Output is correct
14 Correct 30 ms 4076 KB Output is correct
15 Correct 47 ms 5484 KB Output is correct
16 Correct 35 ms 4332 KB Output is correct
17 Correct 17 ms 3436 KB Output is correct