Submission #869271

# Submission time Handle Problem Language Result Execution time Memory
869271 2023-11-03T23:16:48 Z MinaRagy06 Gardening (RMI21_gardening) C++17
0 / 100
12 ms 856 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
 
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int t;
	cin >> t;
	while (t--) {
		int n, m, k;
		cin >> n >> m >> k;
		int mx = (n / 2) * (m / 2);
		if (k > mx || n % 2 || m % 2 || n * m / 4 != k) {
			cout << "NO\n";
			continue;
		}
		bool swapped = 0;
		if (n < m) swap(n, m), swapped = 1;
		cout << "YES\n";
		int a[n][m]{};
		bool must[n][m]{};
		for (int i = 0; i + 1 < n && k; i += 2) {
			for (int j = 0; j + 1 < m && k; j += 2) {
				a[i][j] = k--;
				must[i][j] = 1;
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (a[i][j]) continue;
				if (i - 1 >= 0 && must[i - 1][j]) {
					a[i][j] = a[i - 1][j];
					must[i][j] = 1;
				} else if (j - 1 >= 0) {
					a[i][j] = a[i][j - 1];
				} else if (i - 1 >= 0) {
					a[i][j] = a[i - 1][j];
				}
			}
		}
		if (swapped) {
			for (int j = 0; j < m; j++) {
				for (int i = 0; i < n; i++) {
					cout << a[i][j] << ' ';
				}
				cout << '\n';
			}
		} else {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					cout << a[i][j] << ' ';
				}
				cout << '\n';
			}
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Failed 12 ms 856 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 12 ms 856 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 12 ms 856 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 0 ms 388 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 0 ms 348 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 12 ms 856 KB Incorrect output
2 Halted 0 ms 0 KB -