Submission #850866

#TimeUsernameProblemLanguageResultExecution timeMemory
850866ItamarGardening (RMI21_gardening)C++14
100 / 100
17 ms1368 KiB
// garden.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include <iostream> using namespace std; #include <vector> #define vi vector<int> bool pos(int l1,int r1, int l2,int r2, int k,int c, vector<vi>& ans) { int n = (r1 - l1 + 1), m = (r2 - l2 + 1); if (n <= 0 || m <= 0)return 1; if (n % 2 || m % 2 || (n == m && k == (n / 2) + 1)||4 * k > n * m || k == ((n * m) / 4) - 1 || k < max(n / 2, m / 2) || (min(n, m) == 2 && k != max(n, m) / 2)) { return 0; } for (int i = l1; i <= r1; i++) { for (int j = l2; j <= l2 + 1; j++) { ans[i][j] = c + (i - l1) / 2; } } l2 += 2; k -= n / 2; c += n / 2; if (pos(l1, r1, l2, r2, k, c, ans))return 1; l2 -= 2; k += n / 2; c -= n / 2; for (int i = l1; i <= l1 + 1; i++) { for (int j = l2; j <= r2; j++) { ans[i][j] = c + (j - l2) / 2; } } l1 += 2; k -= m / 2; c += m / 2; if (pos(l1, r1, l2, r2, k, c, ans))return 1; l1 -= 2; k += m / 2; c -= m / 2; for (int i = l1; i <= r1; i++) { ans[i][l2] = c; ans[i][r2] = c; } for (int j = l2; j <= r2; j++) { ans[l1][j] = c; ans[r1][j] = c; } k--, c++, l1++, l2++, r1--, r2--; return pos(l1, r1, l2, r2, k, c, ans); } int main() { int t; cin >> t; ios_base::sync_with_stdio(false); cin.tie(NULL); for (int i = 0; i < t; i++) { int n, m, k; cin >> n >> m >> k; if (n % 2 || m % 2 || (n == m && k == (n / 2) + 1) || 4 * k > n * m || k == ((n * m) / 4) - 1 || k < max(n / 2, m / 2) || (min(n, m) == 2 && k != max(n, m) / 2)) { cout << "NO" << "\n"; continue; } cout << "YES" << "\n"; vector<vi> ans(n, vi(m)); ans.resize(n, vi(m)); pos(0,n-1,0, m-1, k, 1,ans); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cout << ans[i][j]; if (j < m - 1)cout << ' '; else cout << "\n"; } } } } // Run program: Ctrl + F5 or Debug > Start Without Debugging menu // Debug program: F5 or Debug > Start Debugging menu // Tips for Getting Started: // 1. Use the Solution Explorer window to add/manage files // 2. Use the Team Explorer window to connect to source control // 3. Use the Output window to see build output and other messages // 4. Use the Error List window to view errors // 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project // 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
#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...