답안 #1095599

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095599 2024-10-02T16:16:48 Z peti1234 Gardening (RMI21_gardening) C++17
0 / 100
48 ms 5516 KB
#include <bits/stdc++.h>

using namespace std;
const int c=200005;
vector<int> ans[c];
bool jo(int n, int m, int k) {
	int a=max(n, m)/2, b=n*m/4;
	if (n%2 || m%2 || k<a || k>b || k==b-1 || (n==m && k==a+1)) return false;
	return true;
}
void rec(int n1, int n2, int m1, int m2, int k) {
	int n=n2-n1+1, m=m2-m1+1;
	if (n==0 || m==0) {
		return;
	}
	if (jo(n-2, m-2, k-1)) {
		for (int i=n1; i<=n2; i++) {
			ans[i][m1]=k, ans[i][m2]=k;
		}
		for (int i=m1; i<=m2; i++) {
			ans[n1][i]=k, ans[n2][i]=k;
		}
		return rec(n1+1, n2-1, m1+1, m2-1, k-1);
	}
	if (jo(n-2, m, k-(m/2))) {
		for (int i=m1; i<=m2; i+=2) {
			ans[n1][i]=ans[n1][i+1]=ans[n1+1][i]=ans[n1+1][i+1]=k;
			k--;
		}
		return rec(n1+2, n2, m1, m2, k);
	}
	/*
	if (jo(n, m-2, k-(n/2))) {
		for (int i=n1; i<=n2; i+=2) {
			ans[i][m1]=ans[i+1][m1]=ans[i][m1+1]=ans[i+1][m1+1]=k;
			k--;
		}
		return rec(n1, n2, m1+2, m2, k);
	}
	*/
}
void solve() {
	int n, m, k;
	cin >> n >> m >> k;
	if (!jo(n, m, k)) {
		cout << "NO\n";
		return;
	}
	for (int i=1; i<=n; i++) {
		ans[i].resize(m+1);
	}
	rec(1, n, 1, m, k);
	
	cout << "YES\n";
	for (int i=1; i<=n; i++) {
		for (int j=1; j<=m; j++) {
			cout << ans[i][j] << " ";
		}
		cout << "\n";
	}
}
int main() {
	ios_base::sync_with_stdio(false);
	int w;
	cin >> w;
	while (w--) {
		solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Failed 48 ms 5516 KB Output contains values not between 1 and k
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 48 ms 5516 KB Output contains values not between 1 and k
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 48 ms 5516 KB Output contains values not between 1 and k
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 8 ms 5468 KB Output contains values not between 1 and k
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 4 ms 5212 KB Output contains values not between 1 and k
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 48 ms 5516 KB Output contains values not between 1 and k
2 Halted 0 ms 0 KB -