답안 #737023

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
737023 2023-05-06T13:26:13 Z mjhmjh1104 Gardening (RMI21_gardening) C++17
100 / 100
22 ms 792 KB
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int t, n, m;
long long s;
bool sw;
vector<vector<int>> v, u;

inline void init() {
    v.clear();
    v.resize(n);
    for (int i = 0; i < n; i++) v[i].resize(m);
}

void print() {
    puts("YES");
    if (sw) {
        swap(n, m);
        u.clear();
        u.resize(n);
        for (int i = 0; i < n; i++) u[i].resize(m);
        for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) u[i][j] = v[j][i];
        v = u;
    }
    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 (x <= 1 || y <= 1) return false;
    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 || x < 3) 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);
        sw = false;
        if (n > m) swap(n, m), sw = true;
        if (n % 2 || m % 2 || s > 200000) {
            puts("NO");
            continue;
        }
        if (solve(n / 2, m / 2, s)) continue;
        puts("NO");
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:126:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  126 |     for (scanf("%d", &t); t--; ) {
      |          ~~~~~^~~~~~~~~~
Main.cpp:127:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  127 |         scanf("%d%d%lld", &n, &m, &s);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 688 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 688 KB Correct! Azusa and Laika like the garden :)
2 Correct 13 ms 468 KB Correct! Azusa and Laika like the garden :)
3 Correct 10 ms 592 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 688 KB Correct! Azusa and Laika like the garden :)
2 Correct 13 ms 468 KB Correct! Azusa and Laika like the garden :)
3 Correct 10 ms 592 KB Correct! Azusa and Laika like the garden :)
4 Correct 10 ms 596 KB Correct! Azusa and Laika like the garden :)
5 Correct 13 ms 600 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 596 KB Correct! Azusa and Laika like the garden :)
2 Correct 12 ms 512 KB Correct! Azusa and Laika like the garden :)
3 Correct 12 ms 596 KB Correct! Azusa and Laika like the garden :)
4 Correct 10 ms 540 KB Correct! Azusa and Laika like the garden :)
5 Correct 9 ms 596 KB Correct! Azusa and Laika like the garden :)
6 Correct 9 ms 596 KB Correct! Azusa and Laika like the garden :)
7 Correct 10 ms 572 KB Correct! Azusa and Laika like the garden :)
8 Correct 9 ms 468 KB Correct! Azusa and Laika like the garden :)
9 Correct 11 ms 524 KB Correct! Azusa and Laika like the garden :)
10 Correct 10 ms 596 KB Correct! Azusa and Laika like the garden :)
11 Correct 9 ms 528 KB Correct! Azusa and Laika like the garden :)
12 Correct 9 ms 596 KB Correct! Azusa and Laika like the garden :)
13 Correct 9 ms 476 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 340 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 468 KB Correct! Azusa and Laika like the garden :)
5 Correct 6 ms 468 KB Correct! Azusa and Laika like the garden :)
6 Correct 4 ms 340 KB Correct! Azusa and Laika like the garden :)
7 Correct 4 ms 340 KB Correct! Azusa and Laika like the garden :)
8 Correct 4 ms 460 KB Correct! Azusa and Laika like the garden :)
9 Correct 4 ms 468 KB Correct! Azusa and Laika like the garden :)
10 Correct 4 ms 408 KB Correct! Azusa and Laika like the garden :)
11 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
12 Correct 5 ms 468 KB Correct! Azusa and Laika like the garden :)
13 Correct 4 ms 424 KB Correct! Azusa and Laika like the garden :)
14 Correct 4 ms 340 KB Correct! Azusa and Laika like the garden :)
15 Correct 4 ms 340 KB Correct! Azusa and Laika like the garden :)
16 Correct 4 ms 340 KB Correct! Azusa and Laika like the garden :)
17 Correct 4 ms 348 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 688 KB Correct! Azusa and Laika like the garden :)
2 Correct 13 ms 468 KB Correct! Azusa and Laika like the garden :)
3 Correct 10 ms 592 KB Correct! Azusa and Laika like the garden :)
4 Correct 10 ms 596 KB Correct! Azusa and Laika like the garden :)
5 Correct 13 ms 600 KB Correct! Azusa and Laika like the garden :)
6 Correct 10 ms 596 KB Correct! Azusa and Laika like the garden :)
7 Correct 12 ms 512 KB Correct! Azusa and Laika like the garden :)
8 Correct 12 ms 596 KB Correct! Azusa and Laika like the garden :)
9 Correct 10 ms 540 KB Correct! Azusa and Laika like the garden :)
10 Correct 9 ms 596 KB Correct! Azusa and Laika like the garden :)
11 Correct 9 ms 596 KB Correct! Azusa and Laika like the garden :)
12 Correct 10 ms 572 KB Correct! Azusa and Laika like the garden :)
13 Correct 9 ms 468 KB Correct! Azusa and Laika like the garden :)
14 Correct 11 ms 524 KB Correct! Azusa and Laika like the garden :)
15 Correct 10 ms 596 KB Correct! Azusa and Laika like the garden :)
16 Correct 9 ms 528 KB Correct! Azusa and Laika like the garden :)
17 Correct 9 ms 596 KB Correct! Azusa and Laika like the garden :)
18 Correct 9 ms 476 KB Correct! Azusa and Laika like the garden :)
19 Correct 6 ms 340 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 468 KB Correct! Azusa and Laika like the garden :)
23 Correct 6 ms 468 KB Correct! Azusa and Laika like the garden :)
24 Correct 4 ms 340 KB Correct! Azusa and Laika like the garden :)
25 Correct 4 ms 340 KB Correct! Azusa and Laika like the garden :)
26 Correct 4 ms 460 KB Correct! Azusa and Laika like the garden :)
27 Correct 4 ms 468 KB Correct! Azusa and Laika like the garden :)
28 Correct 4 ms 408 KB Correct! Azusa and Laika like the garden :)
29 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
30 Correct 5 ms 468 KB Correct! Azusa and Laika like the garden :)
31 Correct 4 ms 424 KB Correct! Azusa and Laika like the garden :)
32 Correct 4 ms 340 KB Correct! Azusa and Laika like the garden :)
33 Correct 4 ms 340 KB Correct! Azusa and Laika like the garden :)
34 Correct 4 ms 340 KB Correct! Azusa and Laika like the garden :)
35 Correct 4 ms 348 KB Correct! Azusa and Laika like the garden :)
36 Correct 15 ms 780 KB Correct! Azusa and Laika like the garden :)
37 Correct 14 ms 704 KB Correct! Azusa and Laika like the garden :)
38 Correct 16 ms 724 KB Correct! Azusa and Laika like the garden :)
39 Correct 14 ms 724 KB Correct! Azusa and Laika like the garden :)
40 Correct 14 ms 772 KB Correct! Azusa and Laika like the garden :)
41 Correct 13 ms 684 KB Correct! Azusa and Laika like the garden :)
42 Correct 14 ms 684 KB Correct! Azusa and Laika like the garden :)
43 Correct 13 ms 724 KB Correct! Azusa and Laika like the garden :)
44 Correct 14 ms 780 KB Correct! Azusa and Laika like the garden :)
45 Correct 12 ms 724 KB Correct! Azusa and Laika like the garden :)
46 Correct 14 ms 736 KB Correct! Azusa and Laika like the garden :)
47 Correct 14 ms 740 KB Correct! Azusa and Laika like the garden :)
48 Correct 14 ms 724 KB Correct! Azusa and Laika like the garden :)
49 Correct 14 ms 724 KB Correct! Azusa and Laika like the garden :)
50 Correct 13 ms 700 KB Correct! Azusa and Laika like the garden :)
51 Correct 12 ms 724 KB Correct! Azusa and Laika like the garden :)
52 Correct 14 ms 744 KB Correct! Azusa and Laika like the garden :)
53 Correct 14 ms 792 KB Correct! Azusa and Laika like the garden :)
54 Correct 13 ms 744 KB Correct! Azusa and Laika like the garden :)
55 Correct 14 ms 756 KB Correct! Azusa and Laika like the garden :)
56 Correct 13 ms 724 KB Correct! Azusa and Laika like the garden :)
57 Correct 14 ms 720 KB Correct! Azusa and Laika like the garden :)
58 Correct 13 ms 680 KB Correct! Azusa and Laika like the garden :)
59 Correct 13 ms 724 KB Correct! Azusa and Laika like the garden :)
60 Correct 15 ms 724 KB Correct! Azusa and Laika like the garden :)