Submission #742606

# Submission time Handle Problem Language Result Execution time Memory
742606 2023-05-16T15:14:07 Z siewjh Gardening (RMI21_gardening) C++17
100 / 100
18 ms 852 KB
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> ans;
int c;
bool ok(int rows, int cols, int grps){
	int mxg = rows * cols / 4, mng = max(rows / 2, cols / 2);
	return !(rows & 1 || cols & 1 || grps < mng || grps > mxg || grps == mxg - 1 || (rows == cols && grps == mng + 1));
}
void solve(int rows, int cols, int grps, int rind, int cind){
	if (rows == 2){
		for (int k = 0; k < cols; k += 2){
			c++;
			for (int i = 0; i < 2; i++)
				for (int j = 0; j < 2; j++)
					ans[rind + i][cind + k + j] = c;
		}
	}
	else if (cols == 2){
		for (int k = 0; k < rows; k += 2){
			c++;
			for (int i = 0; i < 2; i++)
				for (int j = 0; j < 2; j++)
					ans[rind + k + i][cind + j] = c;
		}
	}
	else if (ok(rows - 2, cols - 2, grps - 1)){
		c++;
		for (int i = 0; i < rows; i++) ans[rind + i][cind] = ans[rind + i][cind + cols - 1] = c;
		for (int i = 0; i < cols; i++) ans[rind][cind + i] = ans[rind + rows - 1][cind + i] = c;
		solve(rows - 2, cols - 2, grps - 1, rind + 1, cind + 1);
	}
	else if (ok(rows, cols - 2, grps - rows / 2)){
		for (int k = 0; k < rows; k += 2){
			c++;
			for (int i = 0; i < 2; i++)
				for (int j = 0; j < 2; j++)
					ans[rind + k + i][cind + j] = c;
		}
		solve(rows, cols - 2, grps - rows / 2, rind, cind + 2);
	}
	else{
		for (int k = 0; k < cols; k += 2){
			c++;
			for (int i = 0; i < 2; i++)
				for (int j = 0; j < 2; j++)
					ans[rind + i][cind + k + j] = c;
		}
		solve(rows - 2, cols, grps - cols / 2, rind + 2, cind);
	}
}
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 (!ok(rows, cols, grps)){
			cout << "NO\n";
			continue;
		}
		ans = vector<vector<int>>(rows, vector<int>(cols));
		c = 0;
		solve(rows, cols, grps, 0, 0);
		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 time Memory Grader output
1 Correct 18 ms 840 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 18 ms 840 KB Correct! Azusa and Laika like the garden :)
2 Correct 10 ms 596 KB Correct! Azusa and Laika like the garden :)
3 Correct 10 ms 680 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 18 ms 840 KB Correct! Azusa and Laika like the garden :)
2 Correct 10 ms 596 KB Correct! Azusa and Laika like the garden :)
3 Correct 10 ms 680 KB Correct! Azusa and Laika like the garden :)
4 Correct 10 ms 596 KB Correct! Azusa and Laika like the garden :)
5 Correct 10 ms 568 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 9 ms 580 KB Correct! Azusa and Laika like the garden :)
2 Correct 8 ms 596 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 576 KB Correct! Azusa and Laika like the garden :)
4 Correct 10 ms 596 KB Correct! Azusa and Laika like the garden :)
5 Correct 8 ms 596 KB Correct! Azusa and Laika like the garden :)
6 Correct 8 ms 580 KB Correct! Azusa and Laika like the garden :)
7 Correct 9 ms 712 KB Correct! Azusa and Laika like the garden :)
8 Correct 8 ms 596 KB Correct! Azusa and Laika like the garden :)
9 Correct 8 ms 596 KB Correct! Azusa and Laika like the garden :)
10 Correct 9 ms 596 KB Correct! Azusa and Laika like the garden :)
11 Correct 8 ms 596 KB Correct! Azusa and Laika like the garden :)
12 Correct 11 ms 656 KB Correct! Azusa and Laika like the garden :)
13 Correct 8 ms 596 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 4 ms 448 KB Correct! Azusa and Laika like the garden :)
2 Correct 4 ms 340 KB Correct! Azusa and Laika like the garden :)
3 Correct 4 ms 340 KB Correct! Azusa and Laika like the garden :)
4 Correct 5 ms 448 KB Correct! Azusa and Laika like the garden :)
5 Correct 6 ms 468 KB Correct! Azusa and Laika like the garden :)
6 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
7 Correct 4 ms 468 KB Correct! Azusa and Laika like the garden :)
8 Correct 4 ms 468 KB Correct! Azusa and Laika like the garden :)
9 Correct 5 ms 468 KB Correct! Azusa and Laika like the garden :)
10 Correct 5 ms 468 KB Correct! Azusa and Laika like the garden :)
11 Correct 3 ms 316 KB Correct! Azusa and Laika like the garden :)
12 Correct 4 ms 444 KB Correct! Azusa and Laika like the garden :)
13 Correct 4 ms 448 KB Correct! Azusa and Laika like the garden :)
14 Correct 4 ms 468 KB Correct! Azusa and Laika like the garden :)
15 Correct 3 ms 444 KB Correct! Azusa and Laika like the garden :)
16 Correct 4 ms 468 KB Correct! Azusa and Laika like the garden :)
17 Correct 4 ms 444 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 18 ms 840 KB Correct! Azusa and Laika like the garden :)
2 Correct 10 ms 596 KB Correct! Azusa and Laika like the garden :)
3 Correct 10 ms 680 KB Correct! Azusa and Laika like the garden :)
4 Correct 10 ms 596 KB Correct! Azusa and Laika like the garden :)
5 Correct 10 ms 568 KB Correct! Azusa and Laika like the garden :)
6 Correct 9 ms 580 KB Correct! Azusa and Laika like the garden :)
7 Correct 8 ms 596 KB Correct! Azusa and Laika like the garden :)
8 Correct 8 ms 576 KB Correct! Azusa and Laika like the garden :)
9 Correct 10 ms 596 KB Correct! Azusa and Laika like the garden :)
10 Correct 8 ms 596 KB Correct! Azusa and Laika like the garden :)
11 Correct 8 ms 580 KB Correct! Azusa and Laika like the garden :)
12 Correct 9 ms 712 KB Correct! Azusa and Laika like the garden :)
13 Correct 8 ms 596 KB Correct! Azusa and Laika like the garden :)
14 Correct 8 ms 596 KB Correct! Azusa and Laika like the garden :)
15 Correct 9 ms 596 KB Correct! Azusa and Laika like the garden :)
16 Correct 8 ms 596 KB Correct! Azusa and Laika like the garden :)
17 Correct 11 ms 656 KB Correct! Azusa and Laika like the garden :)
18 Correct 8 ms 596 KB Correct! Azusa and Laika like the garden :)
19 Correct 4 ms 448 KB Correct! Azusa and Laika like the garden :)
20 Correct 4 ms 340 KB Correct! Azusa and Laika like the garden :)
21 Correct 4 ms 340 KB Correct! Azusa and Laika like the garden :)
22 Correct 5 ms 448 KB Correct! Azusa and Laika like the garden :)
23 Correct 6 ms 468 KB Correct! Azusa and Laika like the garden :)
24 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
25 Correct 4 ms 468 KB Correct! Azusa and Laika like the garden :)
26 Correct 4 ms 468 KB Correct! Azusa and Laika like the garden :)
27 Correct 5 ms 468 KB Correct! Azusa and Laika like the garden :)
28 Correct 5 ms 468 KB Correct! Azusa and Laika like the garden :)
29 Correct 3 ms 316 KB Correct! Azusa and Laika like the garden :)
30 Correct 4 ms 444 KB Correct! Azusa and Laika like the garden :)
31 Correct 4 ms 448 KB Correct! Azusa and Laika like the garden :)
32 Correct 4 ms 468 KB Correct! Azusa and Laika like the garden :)
33 Correct 3 ms 444 KB Correct! Azusa and Laika like the garden :)
34 Correct 4 ms 468 KB Correct! Azusa and Laika like the garden :)
35 Correct 4 ms 444 KB Correct! Azusa and Laika like the garden :)
36 Correct 12 ms 708 KB Correct! Azusa and Laika like the garden :)
37 Correct 12 ms 752 KB Correct! Azusa and Laika like the garden :)
38 Correct 12 ms 704 KB Correct! Azusa and Laika like the garden :)
39 Correct 13 ms 744 KB Correct! Azusa and Laika like the garden :)
40 Correct 12 ms 804 KB Correct! Azusa and Laika like the garden :)
41 Correct 13 ms 700 KB Correct! Azusa and Laika like the garden :)
42 Correct 16 ms 852 KB Correct! Azusa and Laika like the garden :)
43 Correct 12 ms 852 KB Correct! Azusa and Laika like the garden :)
44 Correct 12 ms 724 KB Correct! Azusa and Laika like the garden :)
45 Correct 12 ms 764 KB Correct! Azusa and Laika like the garden :)
46 Correct 12 ms 724 KB Correct! Azusa and Laika like the garden :)
47 Correct 12 ms 724 KB Correct! Azusa and Laika like the garden :)
48 Correct 12 ms 796 KB Correct! Azusa and Laika like the garden :)
49 Correct 12 ms 724 KB Correct! Azusa and Laika like the garden :)
50 Correct 13 ms 748 KB Correct! Azusa and Laika like the garden :)
51 Correct 11 ms 724 KB Correct! Azusa and Laika like the garden :)
52 Correct 13 ms 776 KB Correct! Azusa and Laika like the garden :)
53 Correct 14 ms 732 KB Correct! Azusa and Laika like the garden :)
54 Correct 13 ms 724 KB Correct! Azusa and Laika like the garden :)
55 Correct 17 ms 736 KB Correct! Azusa and Laika like the garden :)
56 Correct 14 ms 772 KB Correct! Azusa and Laika like the garden :)
57 Correct 12 ms 724 KB Correct! Azusa and Laika like the garden :)
58 Correct 13 ms 712 KB Correct! Azusa and Laika like the garden :)
59 Correct 13 ms 852 KB Correct! Azusa and Laika like the garden :)
60 Correct 12 ms 852 KB Correct! Azusa and Laika like the garden :)