답안 #794764

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
794764 2023-07-26T22:12:49 Z rainboy Gardening (RMI21_gardening) C
21 / 100
15 ms 672 KB
#include <stdio.h>

#define NM	200000

int max(int a, int b) { return a > b ? a : b; }

int check(int n, int m, int k) {
	if (n % 2 != 0 || m % 2 != 0 || k > n * m / 4 || k < max(n, m) / 2)
		return 0;
	if (k == n * m / 4 - 1)
		return 0;
	if (n == 6 && m == 6 && k == 4)
		return 0;
	return 1;
}

int aa[NM], n_, m_, a_;

void solve(int n, int m, int k, int i_, int j_) {
	int n1, n2, m1, m2, l1, r1, l2, r2, k1, k2, i, j;

	if (n == 2) {
		for (i = 0, j = 0; j < m; j += 2) {
			aa[(i_ + i) * m_ + (j_ + j)] = aa[(i_ + i) * m_ + (j_ + j + 1)] = a_;
			aa[(i_ + i + 1) * m_ + (j_ + j)] = aa[(i_ + i + 1) * m_ + (j_ + j + 1)] = a_;
			a_++;
		}
	} else if (m == 2) {
		for (i = 0, j = 0; i < n; i += 2) {
			aa[(i_ + i) * m_ + (j_ + j)] = aa[(i_ + i) * m_ + (j_ + j + 1)] = a_;
			aa[(i_ + i + 1) * m_ + (j_ + j)] = aa[(i_ + i + 1) * m_ + (j_ + j + 1)] = a_;
			a_++;
		}
	} else if (check(n - 2, m - 2, k - 1)) {
		solve(n - 2, m - 2, k - 1, i_ + 1, j_ + 1);
		for (i = 0; i < n; i++)
			aa[(i_ + i) * m_ + (j_ + 0)] = aa[(i_ + i) * m_ + (j_ + m - 1)] = a_;
		for (j = 0; j < m; j++)
			aa[(i_ + 0) * m_ + (j_ + j)] = aa[(i_ + n - 1) * m_ + (j_ + j)] = a_;
		a_++;
	} else {
		 for (n1 = 2; n1 <= n; n1 += 2) {
			 n2 = n - n1, l1 = max(n1, m) / 2, r1 = n1 * m / 4, l2 = max(n2, m) / 2, r2 = n2 * m / 4;
			 for (k1 = max(l1, k - r2); k1 <= r1 && (k2 = k - k1) >= l2; k1++)
				 if (check(n1, m, k1) && check(n2, m, k2)) {
					 solve(n1, m, k1, i_, j_);
					 solve(n2, m, k2, n1 + i_, j_);
					 return;
				 }
		 }
		 for (m1 = 2; m1 <= m; m1 += 2) {
			 m2 = m - m1, l1 = max(n, m1) / 2, r1 = n * m1 / 4, l2 = max(n, m2) / 2, r2 = n * m2 / 4;
			 for (k1 = max(l1, k - r2); k1 <= r1 && (k2 = k - k1) >= l2; k1++)
				 if (check(n, m1, k1) && check(n, m2, k2)) {
					 solve(n, m1, k1, i_, j_);
					 solve(n, m2, k2, i_, m1 + j_);
					 return;
				 }
		 }
	}
}

int main() {
	int t;

	scanf("%d", &t);
	while (t--) {
		int n, m, k, i, j;

		scanf("%d%d%d", &n, &m, &k), n_ = n, m_ = m;
		if (!check(n, m, k))
			printf("NO\n");
		else {
			a_ = 1, solve(n, m, k, 0, 0);
			printf("YES\n");
			for (i = 0; i < n; i++) {
				for (j = 0; j < m; j++)
					printf("%d ", aa[i * m + j]);
				printf("\n");
			}
		}
	}
	return 0;
}

Compilation message

Main.c: In function 'main':
Main.c:66:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |  scanf("%d", &t);
      |  ^~~~~~~~~~~~~~~
Main.c:70:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |   scanf("%d%d%d", &n, &m, &k), n_ = n, m_ = m;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 672 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 672 KB Correct! Azusa and Laika like the garden :)
2 Correct 11 ms 588 KB Correct! Azusa and Laika like the garden :)
3 Correct 9 ms 576 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 672 KB Correct! Azusa and Laika like the garden :)
2 Correct 11 ms 588 KB Correct! Azusa and Laika like the garden :)
3 Correct 9 ms 576 KB Correct! Azusa and Laika like the garden :)
4 Correct 9 ms 596 KB Correct! Azusa and Laika like the garden :)
5 Correct 9 ms 596 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Failed 11 ms 584 KB Incorrect output
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
2 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
3 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
4 Failed 4 ms 416 KB Incorrect output
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 672 KB Correct! Azusa and Laika like the garden :)
2 Correct 11 ms 588 KB Correct! Azusa and Laika like the garden :)
3 Correct 9 ms 576 KB Correct! Azusa and Laika like the garden :)
4 Correct 9 ms 596 KB Correct! Azusa and Laika like the garden :)
5 Correct 9 ms 596 KB Correct! Azusa and Laika like the garden :)
6 Failed 11 ms 584 KB Incorrect output
7 Halted 0 ms 0 KB -