Submission #1298909

#TimeUsernameProblemLanguageResultExecution timeMemory
1298909NotLinuxGardening (RMI21_gardening)C++20
0 / 100
1096 ms492 KiB
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define all(x) x.begin() , x.end()
int n,m,k,space;
vector<vector<int>>grid;
vector<vector<vector<int>>>ans;
void dfs(int col){
	if(!ans.empty())return;
	// cout << "dfs : " << col << endl;
	// for(int i = 0;i<n;i++){
	// 	for(int j = 0;j<m;j++){
	// 		cout << grid[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }
	// find the first uncolored
	pair<int,int> st = {-1,-1};
	for(int i = 0;i<n;i++){
		for(int j = 0;j<m;j++){
			if(grid[i][j] == -1){
				st = {i,j};
				break;
			}
		}
		if(st != pair<int,int>{-1,-1})break;
	}
	if(col == k){
		if(st == pair<int,int>{-1,-1}){
			ans.push_back(grid);
		}
		return;
	}
	else if(space < (k - col) * 4){
		return;
	}
	for(int x = 2;st.first + x <= n;x+=2){
		for(int y = 2;st.second + y <= m;y+=2){
			if((x == 2 and y != 2) or (y == 2 and x != 2))continue;
			if(space < 2 * (x + y - 2))continue;
			// bunlarin vectorunu cikar
			vector<pair<int,int>>vec;
			for(int i = st.first;i<st.first + x;i++){
				vec.push_back({i , st.second});
				vec.push_back({i , st.second + y - 1});
			}
			for(int j = st.second + 1;j<st.second + y - 1;j++){
				vec.push_back({st.first , j});
				vec.push_back({st.first + x - 1 , j});
			}
			// burda kimse var mi
			bool bl = 1;
			for(auto itr : vec){
				bl &= grid[itr.first][itr.second] == -1;
			}
			if(bl == 0)continue;
			// burayi doldur
			for(auto itr : vec){
				grid[itr.first][itr.second] = col;
			}
			// dallan
			space -= 2 * (x + y - 2); 
			dfs(col+1);
			space += 2 * (x + y - 2);
			// geri don
			for(auto itr : vec){
				grid[itr.first][itr.second] = -1;
			}
		}
	}
}
void solve(){
    cin >> n >> m >> k;
    if(n%2 or m%2 or n*m < 4*k or k < max(n,m) / 2){
    	cout << "NO" << endl;
    	return;
    }
    ans.clear();
    grid.assign(n,vector<int>(m,-1));
    space = n*m;
    dfs(0);
    cout << "YES" << endl;
    // for(auto itr : ans){
    	for(int i = 0;i<n;i++){
    		for(int j = 0;j<m;j++){
    			cout << ans[0][i][j]+1 << " ";
    		}
    		cout << endl;
    	}
    	// cout << endl;
    // }
}
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int testcase=1;cin >> testcase;
	while(testcase--)solve();
	cerr << 1000.0 * clock() / CLOCKS_PER_SEC << " ms" << endl;
}
#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...