Submission #1038814

# Submission time Handle Problem Language Result Execution time Memory
1038814 2024-07-30T07:52:54 Z andrei_c1 Gardening (RMI21_gardening) C++17
100 / 100
172 ms 1876 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int tc, n, m, k, col;

vector<vector<int>> v;
map<ll, bool> can;

ll kN = 2e5;

#define hash sateiadracu

ll hash(int n, int m, int k) {
	return kN * kN * n + kN * m + k;
}

bool check(int n, int m, int k) {
	if(n > m) {
		swap(n, m);
	}
	ll h = hash(n, m, k);
	return can.find(h) != can.end() && can[h];
}

bool solve(int n, int m, int k) {
	if(n % 2 || m % 2) {
		return 0;
	}
	if(k > n * m / 4) {
		return 0;
	}
	if(n > m) {
		swap(n, m);
	}
	if(k < m / 2) {
		return 0;
	}
	ll h = hash(n, m, k);
	if(can.find(h) != can.end()) {
		return can[h];
	}
	if(k == 1) {
		return can[h] = (n == 2 && m == 2);
	}
	// split col
	for(int k1 = 1; k1 < k; k1++) {
		for(int j = 2; j < m - 1; j += 2) {
			if(solve(n, j, k1) && solve(n, m - j, k - k1)) {
				return can[h] = true;
			}
		}
	}
	// slpit border
	if(solve(n - 2, m - 2, k - 1)) {
		return can[h] = true;
	}
	return can[h] = false;
}

void rec(int a, int b, int c, int d, int k) {
	int n = c - a + 1, m = d - b + 1;
	if(n == 1 || m == 1) {
		return;
	}
	if(k == 1) {
		if(n == 2 && m == 2) {
			v[a][b] = v[a][d] = v[c][b] = v[c][d] = col;
			col++;
		}
		return;
	}
	if(check(c - a - 1, d - b - 1, k - 1)) {
		for(int i = b; i <= d; i++) {
			v[a][i] = v[c][i] = col;
		}
		for(int i = a; i <= c; i++) {
			v[i][b] = v[i][d] = col;
		}
		col++;
		rec(a + 1, b + 1, c - 1, d - 1, k - 1);
		return;
	}
	for(int j = b + 1; j < d; j++) {
		for(int k1 = 1; k1 < k; k1++) {
			if(check(c - a + 1, j - b + 1, k1) && check(c - a + 1, d - j, k - k1)) {
				rec(a, b, c, j, k1);
				rec(a, j + 1, c, d, k - k1);
				return;
			}
		}
	}
	for(int j = a + 1; j < c; j++) {
		for(int k1 = 1; k1 < k; k1++) {
			if(check(j - a + 1, d - b + 1, k1) && check(c - j, d - b + 1, k - k1)) {
				rec(a, b, j, d, k1);
				rec(j + 1, b, c, d, k - k1);
				return;
			}
		}
	}
}

void solve() {
	cin >> n >> m >> k;
	can.clear();
	bool ok = solve(n, m, k);
	if(!ok) {
		cout << "NO\n";
		return;
	}
	cout << "YES\n";
	v = vector<vector<int>>(n + 1, vector<int>(m + 1));
	col = 1;
	rec(1, 1, n, m, k);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			cout << v[i][j] << " ";
		}
		cout << "\n";
	}
}

int main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	cin >> tc;
	while(tc--) {
		solve();
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 860 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 15 ms 860 KB Correct! Azusa and Laika like the garden :)
2 Correct 10 ms 604 KB Correct! Azusa and Laika like the garden :)
3 Correct 10 ms 604 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 15 ms 860 KB Correct! Azusa and Laika like the garden :)
2 Correct 10 ms 604 KB Correct! Azusa and Laika like the garden :)
3 Correct 10 ms 604 KB Correct! Azusa and Laika like the garden :)
4 Correct 11 ms 760 KB Correct! Azusa and Laika like the garden :)
5 Correct 12 ms 860 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 63 ms 740 KB Correct! Azusa and Laika like the garden :)
2 Correct 86 ms 992 KB Correct! Azusa and Laika like the garden :)
3 Correct 64 ms 1184 KB Correct! Azusa and Laika like the garden :)
4 Correct 87 ms 860 KB Correct! Azusa and Laika like the garden :)
5 Correct 72 ms 1104 KB Correct! Azusa and Laika like the garden :)
6 Correct 77 ms 852 KB Correct! Azusa and Laika like the garden :)
7 Correct 80 ms 1104 KB Correct! Azusa and Laika like the garden :)
8 Correct 52 ms 848 KB Correct! Azusa and Laika like the garden :)
9 Correct 60 ms 852 KB Correct! Azusa and Laika like the garden :)
10 Correct 62 ms 932 KB Correct! Azusa and Laika like the garden :)
11 Correct 60 ms 852 KB Correct! Azusa and Laika like the garden :)
12 Correct 66 ms 948 KB Correct! Azusa and Laika like the garden :)
13 Correct 64 ms 860 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 30 ms 768 KB Correct! Azusa and Laika like the garden :)
2 Correct 39 ms 852 KB Correct! Azusa and Laika like the garden :)
3 Correct 16 ms 600 KB Correct! Azusa and Laika like the garden :)
4 Correct 43 ms 752 KB Correct! Azusa and Laika like the garden :)
5 Correct 44 ms 1008 KB Correct! Azusa and Laika like the garden :)
6 Correct 19 ms 600 KB Correct! Azusa and Laika like the garden :)
7 Correct 39 ms 724 KB Correct! Azusa and Laika like the garden :)
8 Correct 37 ms 600 KB Correct! Azusa and Laika like the garden :)
9 Correct 28 ms 616 KB Correct! Azusa and Laika like the garden :)
10 Correct 39 ms 856 KB Correct! Azusa and Laika like the garden :)
11 Correct 16 ms 604 KB Correct! Azusa and Laika like the garden :)
12 Correct 19 ms 612 KB Correct! Azusa and Laika like the garden :)
13 Correct 27 ms 600 KB Correct! Azusa and Laika like the garden :)
14 Correct 26 ms 600 KB Correct! Azusa and Laika like the garden :)
15 Correct 35 ms 744 KB Correct! Azusa and Laika like the garden :)
16 Correct 32 ms 604 KB Correct! Azusa and Laika like the garden :)
17 Correct 37 ms 600 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 15 ms 860 KB Correct! Azusa and Laika like the garden :)
2 Correct 10 ms 604 KB Correct! Azusa and Laika like the garden :)
3 Correct 10 ms 604 KB Correct! Azusa and Laika like the garden :)
4 Correct 11 ms 760 KB Correct! Azusa and Laika like the garden :)
5 Correct 12 ms 860 KB Correct! Azusa and Laika like the garden :)
6 Correct 63 ms 740 KB Correct! Azusa and Laika like the garden :)
7 Correct 86 ms 992 KB Correct! Azusa and Laika like the garden :)
8 Correct 64 ms 1184 KB Correct! Azusa and Laika like the garden :)
9 Correct 87 ms 860 KB Correct! Azusa and Laika like the garden :)
10 Correct 72 ms 1104 KB Correct! Azusa and Laika like the garden :)
11 Correct 77 ms 852 KB Correct! Azusa and Laika like the garden :)
12 Correct 80 ms 1104 KB Correct! Azusa and Laika like the garden :)
13 Correct 52 ms 848 KB Correct! Azusa and Laika like the garden :)
14 Correct 60 ms 852 KB Correct! Azusa and Laika like the garden :)
15 Correct 62 ms 932 KB Correct! Azusa and Laika like the garden :)
16 Correct 60 ms 852 KB Correct! Azusa and Laika like the garden :)
17 Correct 66 ms 948 KB Correct! Azusa and Laika like the garden :)
18 Correct 64 ms 860 KB Correct! Azusa and Laika like the garden :)
19 Correct 30 ms 768 KB Correct! Azusa and Laika like the garden :)
20 Correct 39 ms 852 KB Correct! Azusa and Laika like the garden :)
21 Correct 16 ms 600 KB Correct! Azusa and Laika like the garden :)
22 Correct 43 ms 752 KB Correct! Azusa and Laika like the garden :)
23 Correct 44 ms 1008 KB Correct! Azusa and Laika like the garden :)
24 Correct 19 ms 600 KB Correct! Azusa and Laika like the garden :)
25 Correct 39 ms 724 KB Correct! Azusa and Laika like the garden :)
26 Correct 37 ms 600 KB Correct! Azusa and Laika like the garden :)
27 Correct 28 ms 616 KB Correct! Azusa and Laika like the garden :)
28 Correct 39 ms 856 KB Correct! Azusa and Laika like the garden :)
29 Correct 16 ms 604 KB Correct! Azusa and Laika like the garden :)
30 Correct 19 ms 612 KB Correct! Azusa and Laika like the garden :)
31 Correct 27 ms 600 KB Correct! Azusa and Laika like the garden :)
32 Correct 26 ms 600 KB Correct! Azusa and Laika like the garden :)
33 Correct 35 ms 744 KB Correct! Azusa and Laika like the garden :)
34 Correct 32 ms 604 KB Correct! Azusa and Laika like the garden :)
35 Correct 37 ms 600 KB Correct! Azusa and Laika like the garden :)
36 Correct 94 ms 1164 KB Correct! Azusa and Laika like the garden :)
37 Correct 172 ms 1876 KB Correct! Azusa and Laika like the garden :)
38 Correct 69 ms 960 KB Correct! Azusa and Laika like the garden :)
39 Correct 81 ms 1104 KB Correct! Azusa and Laika like the garden :)
40 Correct 100 ms 1148 KB Correct! Azusa and Laika like the garden :)
41 Correct 116 ms 1104 KB Correct! Azusa and Laika like the garden :)
42 Correct 113 ms 1104 KB Correct! Azusa and Laika like the garden :)
43 Correct 84 ms 1092 KB Correct! Azusa and Laika like the garden :)
44 Correct 79 ms 1152 KB Correct! Azusa and Laika like the garden :)
45 Correct 93 ms 1108 KB Correct! Azusa and Laika like the garden :)
46 Correct 79 ms 1108 KB Correct! Azusa and Laika like the garden :)
47 Correct 141 ms 1772 KB Correct! Azusa and Laika like the garden :)
48 Correct 87 ms 1108 KB Correct! Azusa and Laika like the garden :)
49 Correct 107 ms 1204 KB Correct! Azusa and Laika like the garden :)
50 Correct 91 ms 1104 KB Correct! Azusa and Laika like the garden :)
51 Correct 93 ms 1616 KB Correct! Azusa and Laika like the garden :)
52 Correct 89 ms 1088 KB Correct! Azusa and Laika like the garden :)
53 Correct 76 ms 1044 KB Correct! Azusa and Laika like the garden :)
54 Correct 78 ms 1104 KB Correct! Azusa and Laika like the garden :)
55 Correct 83 ms 1180 KB Correct! Azusa and Laika like the garden :)
56 Correct 125 ms 1104 KB Correct! Azusa and Laika like the garden :)
57 Correct 89 ms 1104 KB Correct! Azusa and Laika like the garden :)
58 Correct 103 ms 1692 KB Correct! Azusa and Laika like the garden :)
59 Correct 102 ms 1144 KB Correct! Azusa and Laika like the garden :)
60 Correct 102 ms 1108 KB Correct! Azusa and Laika like the garden :)