Submission #742469

#TimeUsernameProblemLanguageResultExecution timeMemory
742469siewjhGardening (RMI21_gardening)C++17
11 / 100
29 ms708 KiB
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int cases; cin >> cases;
	while (cases--){
		int rows, cols, grps; cin >> rows >> cols >> grps;
		if (rows % 2 == 1 || cols % 2 == 1){
			cout << "NO\n";
			continue;
		}
		int mxg = rows * cols / 4, mng;
		vector<vector<int>> ans(rows, vector<int>(cols));
		if (rows == 2){
			if (grps != mxg){
				cout << "NO\n";
				continue;
			}
			int c = 0;
			for (int j = 0; j < cols; j += 2){
				c++;
				ans[0][j] = ans[1][j] = ans[0][j + 1] = ans[1][j + 1] = c;
			}
		}
		else {
			if (cols % 4 == 0){
				mng = cols / 4 * 2;
				if (grps < mng || grps > mxg || grps == mxg - 1){
					cout << "NO\n";
					continue;
				}
				int c = 0;
				for (int j = 0; j < cols; j += 4){
					if (mng + 2 <= grps){
						mng += 2;
						for (int kr = 0; kr <= 2; kr += 2){
							for (int kc = 0; kc <= 2; kc += 2){
								c++;
								for (int lr = 0; lr < 2; lr++)
									for (int lc = 0; lc < 2; lc++)
										ans[kr + lr][j + kc + lc] = c;
							}
						}
					}
					else{
						c++;
						for (int i = 0; i < 4; i++) ans[i][j] = ans[i][j + 3] = ans[0][j + i] = ans[3][j + i] = c;
						c++;
						ans[1][j + 1] = ans[1][j + 2] = ans[2][j + 1] = ans[2][j + 2] = c;
					}
				}
				if (mng + 1 == grps){
					c++;
					for (int i = 0; i < 2; i++)
						for (int j = 0; j < 2; j++){
							ans[1 + i][cols - 5 + j] = c;
						}
					ans[0][cols - 4] = ans[0][cols - 3] = ans[1][cols - 3] = ans[2][cols - 3] = ans[3][cols - 3] = ans[3][cols - 4] = c - 4;
					for (int i = 0; i < 2; i++)
						for (int j = 0; j < 2; j++){
							ans[i][cols - 2 + j] = c - 2;
						}
					for (int i = 0; i < 2; i++)
						for (int j = 0; j < 2; j++){
							ans[2 + i][cols - 2 + j] = c - 1;
						}
				}
			}
			else{
				mng = cols / 4 * 2 + 1;
				if (grps < mng || grps > mxg || grps == mxg - 1){
					cout << "NO\n";
					continue;
				}
				int c = 0;
				for (int j = 0; j < cols - 2; j += 4){
					if (mng + 2 <= grps){
						mng += 2;
						for (int kr = 0; kr <= 2; kr += 2){
							for (int kc = 0; kc <= 2; kc += 2){
								c++;
								for (int lr = 0; lr < 2; lr++)
									for (int lc = 0; lc < 2; lc++)
										ans[kr + lr][j + kc + lc] = c;
							}
						}
					}
					else{
						c++;
						for (int i = 0; i < 4; i++) ans[i][j] = ans[i][j + 3] = ans[0][j + i] = ans[3][j + i] = c;
						c++;
						ans[1][j + 1] = ans[1][j + 2] = ans[2][j + 1] = ans[2][j + 2] = c;
					}
				}
				if (mng + 1 == grps){
					c++;
					for (int i = 0; i < 2; i++)
						for (int j = 0; j < 2; j++){
							ans[i][cols - 2 + j] = c;
						}
					c++;
					for (int i = 0; i < 2; i++)
						for (int j = 0; j < 2; j++){
							ans[2 + i][cols - 2 + j] = c;
						}
				}
				else{
					c++;
					for (int i = 0; i < 2; i++)
						for (int j = 0; j < 2; j++){
							ans[1 + i][cols - 3 + j] = c;
						}
					ans[0][cols - 2] = ans[0][cols - 1] = ans[1][cols - 1] = ans[2][cols - 1] = ans[3][cols - 1] = ans[3][cols - 2] = c - 2;
				}
			}
		}
		cout << "YES\n";
		for (int i = 0; i < rows; i++){
			for (int j = 0; j < cols; j++) cout << ans[i][j] << ' ';
			cout << '\n';
		}
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...