# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
737016 | 2023-05-06T13:15:17 Z | mjhmjh1104 | Gardening (RMI21_gardening) | C++17 | 22 ms | 636 KB |
#include <cstdio> #include <vector> using namespace std; int t, n, m; long long s; vector<vector<int>> v; inline void init() { v.clear(); v.resize(n); for (int i = 0; i < n; i++) v[i].resize(m); } void print() { puts("YES"); for (auto &i: v) { for (auto &j: i) printf("%d ", j + 1); puts(""); } } bool solve(int x, int y, int z, int step = 0) { if (x <= 0 || y <= 0) return false; if (z == x * y) { init(); for (int i = 0; i < step; i++) { for (int j = i; j < m - i; j++) v[i][j] = v[n - 1 - i][j] = i; for (int j = i; j < n - i; j++) v[j][i] = v[j][m - 1 - i] = i; } for (int i = 0; i < x; i++) for (int j = 0; j < y; j++) { int curr = step + i * y + j; v[step + i * 2][step + j * 2] = v[step + i * 2][step + j * 2 + 1] = v[step + i * 2 + 1][step + j * 2] = v[step + i * 2 + 1][step + j * 2 + 1] = curr; } print(); return true; } if (z == x * y - 1) return false; if (z <= x * y && z >= x * y - x) { int cnt = x * y - z - 1; init(); for (int i = 0; i < step; i++) { for (int j = i; j < m - i; j++) v[i][j] = v[n - 1 - i][j] = i; for (int j = i; j < n - i; j++) v[j][i] = v[j][m - 1 - i] = i; } v[step][step] = v[step][step + 1] = v[step][step + 2] = v[step][step + 3] = step; v[step + cnt * 2 + 1][step] = v[step + cnt * 2 + 1][step + 1] = v[step + cnt * 2 + 1][step + 2] = v[step + cnt * 2 + 1][step + 3] = step; for (int i = 0; i < cnt; i++) { v[step + i * 2 + 1][step] = v[step + i * 2 + 1][step + 3] = step; v[step + i * 2 + 2][step] = v[step + i * 2 + 2][step + 3] = step; v[step + i * 2 + 1][step + 1] = v[step + i * 2 + 1][step + 2] = step + i + 1; v[step + i * 2 + 2][step + 1] = v[step + i * 2 + 2][step + 2] = step + i + 1; } int k = step + cnt + 1; for (int i = 0; i < x; i++) for (int j = 0; j < y; j++) { if (i <= cnt && j <= 1) continue; v[step + i * 2][step + j * 2] = v[step + i * 2][step + j * 2 + 1] = v[step + i * 2 + 1][step + j * 2] = v[step + i * 2 + 1][step + j * 2 + 1] = k++; } print(); return true; } if (z <= x * y && z >= x * y - x - y + 3) { int cnt = x * y - z - x + 1; init(); for (int i = 0; i < step; i++) { for (int j = i; j < m - i; j++) v[i][j] = v[n - 1 - i][j] = i; for (int j = i; j < n - i; j++) v[j][i] = v[j][m - 1 - i] = i; } for (int i = 0; i <= cnt; i++) v[step][step + i * 2] = v[step][step + i * 2 + 1] = step; for (int i = 0; i <= cnt; i++) v[n - 1 - step][step + i * 2] = v[n - 1 - step][step + i * 2 + 1] = step; int k = step + 1; for (int i = 0; i < n / 2 - step - 1; i++) { v[step + i * 2 + 1][step] = v[step + i * 2 + 1][step + cnt * 2 + 1] = step; v[step + i * 2 + 2][step] = v[step + i * 2 + 2][step + cnt * 2 + 1] = step; for (int j = step + 1; j < step + cnt * 2 + 1; j += 2) v[step + i * 2 + 1][j] = v[step + i * 2 + 2][j] = v[step + i * 2 + 1][j + 1] = v[step + i * 2 + 2][j + 1] = k++; } for (int i = 0; i < x; i++) for (int j = 0; j < y; j++) { if (j <= cnt) continue; v[step + i * 2][step + j * 2] = v[step + i * 2][step + j * 2 + 1] = v[step + i * 2 + 1][step + j * 2] = v[step + i * 2 + 1][step + j * 2 + 1] = k++; } print(); return true; } if (z == x * y - x - y + 1) { int cnt = m / 2 - step - 2; if (cnt < 2) return false; init(); for (int i = 0; i < step; i++) { for (int j = i; j < m - i; j++) v[i][j] = v[n - 1 - i][j] = i; for (int j = i; j < n - i; j++) v[j][i] = v[j][m - 1 - i] = i; } for (int i = 0; i <= cnt; i++) v[step][step + i * 2] = v[step][step + i * 2 + 1] = step; for (int i = 0; i <= cnt; i++) v[n - 1 - step][step + i * 2] = v[n - 1 - step][step + i * 2 + 1] = step; v[step + 1][step + 1] = v[step + 1][step + 2] = v[step + 1][step + 3] = v[step + 1][step + 4] = step + 1; v[step + 4][step + 1] = v[step + 4][step + 2] = v[step + 4][step + 3] = v[step + 4][step + 4] = step + 1; v[step + 2][step + 1] = v[step + 2][step + 4] = v[step + 3][step + 1] = v[step + 3][step + 4] = step + 1; v[step + 2][step + 2] = v[step + 2][step + 3] = v[step + 3][step + 2] = v[step + 3][step + 3] = step + 2; int k = step + 3; for (int i = 0; i < n / 2 - step - 1; i++) { v[step + i * 2 + 1][step] = v[step + i * 2 + 1][step + cnt * 2 + 1] = step; v[step + i * 2 + 2][step] = v[step + i * 2 + 2][step + cnt * 2 + 1] = step; for (int j = step + 1 + (i < 2 ? 4 : 0); j < step + cnt * 2 + 1; j += 2) v[step + i * 2 + 1][j] = v[step + i * 2 + 2][j] = v[step + i * 2 + 1][j + 1] = v[step + i * 2 + 2][j + 1] = k++; } for (int i = 0; i < x; i++) for (int j = 0; j < y; j++) { if (j <= cnt) continue; v[step + i * 2][step + j * 2] = v[step + i * 2][step + j * 2 + 1] = v[step + i * 2 + 1][step + j * 2] = v[step + i * 2 + 1][step + j * 2 + 1] = k++; } print(); return true; } return solve(x - 1, y - 1, z - 1, step + 1); } int main() { for (scanf("%d", &t); t--; ) { scanf("%d%d%lld", &n, &m, &s); if (n % 2 || m % 2 || s > 200000) { puts("NO"); continue; } if (n == 2) { if (s != m / 2) { puts("NO"); continue; } init(); for (int i = 0; i < m / 2; i++) v[0][i * 2] = v[0][i * 2 + 1] = v[1][i * 2] = v[1][i * 2 + 1] = i; print(); continue; } if (n == 4) { int a = m - s; int b = s - m / 2; if (a < 0 || b < 0 || a == 1) { puts("NO"); continue; } init(); if (a) { v[0][0] = v[1][0] = v[2][0] = v[3][0] = 0; v[0][2 * a - 1] = v[1][2 * a - 1] = v[2][2 * a - 1] = v[3][2 * a - 1] = 0; for (int i = 0; i < a - 1; i++) { v[0][i * 2 + 1] = v[0][i * 2 + 2] = v[3][i * 2 + 1] = v[3][i * 2 + 2] = 0; v[1][i * 2 + 1] = v[1][i * 2 + 2] = v[2][i * 2 + 1] = v[2][i * 2 + 2] = i + 1; } } for (int i = 0; i < b; i++) { v[0][a * 2 + i * 2] = v[0][a * 2 + i * 2 + 1] = v[1][a * 2 + i * 2] = v[1][a * 2 + i * 2 + 1] = a + i * 2; v[2][a * 2 + i * 2] = v[2][a * 2 + i * 2 + 1] = v[3][a * 2 + i * 2] = v[3][a * 2 + i * 2 + 1] = a + i * 2 + 1; } print(); continue; } if (solve(n / 2, m / 2, s)) continue; puts("NO"); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 624 KB | Correct! Azusa and Laika like the garden :) |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 624 KB | Correct! Azusa and Laika like the garden :) |
2 | Correct | 11 ms | 572 KB | Correct! Azusa and Laika like the garden :) |
3 | Correct | 13 ms | 596 KB | Correct! Azusa and Laika like the garden :) |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 624 KB | Correct! Azusa and Laika like the garden :) |
2 | Correct | 11 ms | 572 KB | Correct! Azusa and Laika like the garden :) |
3 | Correct | 13 ms | 596 KB | Correct! Azusa and Laika like the garden :) |
4 | Failed | 13 ms | 588 KB | Incorrect output |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 636 KB | Correct! Azusa and Laika like the garden :) |
2 | Correct | 10 ms | 512 KB | Correct! Azusa and Laika like the garden :) |
3 | Correct | 9 ms | 596 KB | Correct! Azusa and Laika like the garden :) |
4 | Correct | 10 ms | 612 KB | Correct! Azusa and Laika like the garden :) |
5 | Correct | 9 ms | 596 KB | Correct! Azusa and Laika like the garden :) |
6 | Correct | 12 ms | 560 KB | Correct! Azusa and Laika like the garden :) |
7 | Correct | 13 ms | 624 KB | Correct! Azusa and Laika like the garden :) |
8 | Correct | 9 ms | 468 KB | Correct! Azusa and Laika like the garden :) |
9 | Correct | 10 ms | 540 KB | Correct! Azusa and Laika like the garden :) |
10 | Correct | 10 ms | 576 KB | Correct! Azusa and Laika like the garden :) |
11 | Correct | 10 ms | 536 KB | Correct! Azusa and Laika like the garden :) |
12 | Correct | 9 ms | 544 KB | Correct! Azusa and Laika like the garden :) |
13 | Correct | 9 ms | 584 KB | Correct! Azusa and Laika like the garden :) |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Failed | 4 ms | 408 KB | Incorrect output |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 624 KB | Correct! Azusa and Laika like the garden :) |
2 | Correct | 11 ms | 572 KB | Correct! Azusa and Laika like the garden :) |
3 | Correct | 13 ms | 596 KB | Correct! Azusa and Laika like the garden :) |
4 | Failed | 13 ms | 588 KB | Incorrect output |
5 | Halted | 0 ms | 0 KB | - |