QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#594515#6309. AqreshiqiaqiayaWA 0ms3660kbC++174.8kb2024-09-28 01:36:072024-09-28 01:36:10

Judging History

你现在查看的是最新测评结果

  • [2024-09-28 01:36:10]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3660kb
  • [2024-09-28 01:36:07]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define int long long
using ll = long long;
mt19937_64 rd(time(0));
template <class K, class C = less<>> using paring_heap = __gnu_pbds::priority_queue<K, C>;
template <class K> using rb_tree = tree<K, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T, class ... A> void debug(const T & t, const A & ... a) { cerr << "[" << t, ((cerr << ", " << a), ...), cerr << "]\n"; }
const ll mod = [](bool n) { return n ? 998244353 : 1e9 + 7; } (1);

auto intceil = [](int n, int m) {
    return (n + m - 1) / m;
};

vector<array<int, 4>> mp = {{1, 1, 1, 0}, {1, 1, 0, 1}, {1, 0, 1, 1}, {0, 1, 1, 1}};
vector<array<int, 2>> D = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

void QAQ() {
    int n, m;
    cin >> n >> m;
    if (n <= 3 || m <= 3) {
        if (n <= 3) {
            cout << n * min(m, intceil(m, 4) * 3) << "\n";
            for (int i = 1, op = 0; i <= n; i++, (op += 1) %= mp.size()) {
                for (int j = 1, idx = 0; j <= m; j++, (idx += 1) %= 4) {
                    cout << mp[op][idx] << " \n"[j == m];
                }
            }
        } else {
            cout << m * min(n, intceil(n, 4) * 3) << "\n";
            vector ans(n + 1, vector<int>(m + 1));
            for (int j = 1, op = 0; j <= m; j++, (op += 1) %= mp.size()) {
                for (int i = 1, idx = 0; i <= n; i++, (idx += 1) %= 4) {
                    ans[i][j] = mp[op][idx];
                }
            }
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    cout << ans[i][j] << " \n"[j == m];
                }
            }
        }
    } else {
        int sum = 0;
        vector ans(n + 1, vector<int>(m + 1)), res(n + 1, vector<int>(m + 1));
        auto dfs = [&](auto && self, int i, int sta) -> void {
            if (i == 3) {
                int cnt = 0, chk = 0;
                for (int i = 1; i <= 3; i++) {
                    for (int j = 1; j <= m; j++) {
                        cnt += res[i][j];
                    }
                }
                auto F = [&](int op) {
                    for (int x = i + 1; x <= n; x++, (op += 1) %= mp.size()) {
                        for (int j = 1, idx = 0; j <= m; j++, (idx += 1) %= 4) {
                            res[x][j] = mp[op][idx];
                            cnt += res[x][j];
                        }
                    }

                    vector vis(n + 1, vector<int>(m + 1));
                    auto find = [&](auto && self, int x, int y) -> void {
                        vis[x][y] = 1, chk++;
                        for (auto & [dx, dy] : D) {
                            int tx = x + dx, ty = y + dy;
                            if (1 <= tx && tx <= n && 1 <= ty && ty <= m && !vis[tx][ty] && res[tx][ty]) {
                                self(self, tx, ty);
                            }
                        }
                    };

                    for (int x = 1; x <= n; x ++) {
                        for (int y = 1; y <= m; y++) {
                            if (!vis[x][y] && res[x][y]) {
                                find(find, x, y);
                                if (chk != cnt) return;
                            }
                        }
                    }
                    for (int x = 1; x + 3 <= n; x++) {
                        for (int y = 1; y <= m; y++) {
                            if (res[x][y] && res[x + 1][y] && res[x + 2][y] && res[x + 3][y]) {
                                return;
                            }
                        }
                    }
                    if (cnt > sum) {
                        sum = cnt;
                        ans = res;
                        return;
                    }
                };

                for (int op = 0; op < 4; op++) {
                    F(op);
                }
            } else {
                for (int op = 0; op < 4; op++) {
                    for (int j = 1, idx = 0; j <= m; j++, (idx += 1) %= 4) {
                        res[i + 1][j] = mp[op][idx];
                    }
                    self(self, i + 1, op);
                }
            }
        };

        dfs(dfs, 0, 0);
        cout << sum << "\n";
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                cout << ans[i][j] << " \n"[j == m];
            }
        }
    }
}

signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    int t = 1;
    cin >> t;
    for (cout << fixed << setprecision(12); t--; QAQ());
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3660kb

input:

3
2 2
3 4
3 8

output:

4
1 1
1 1
9
1 1 1 0
1 1 0 1
1 0 1 1
18
1 1 1 0 1 1 1 0
1 1 0 1 1 1 0 1
1 0 1 1 1 0 1 1

result:

wrong answer Length must be equal to m (test case 1)