QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#866033#8830. Breaking BadMisty7WA 0ms3712kbC++204.6kb2025-01-22 10:58:272025-01-22 10:58:36

Judging History

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

  • [2025-01-22 10:58:36]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3712kb
  • [2025-01-22 10:58:27]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n;
    std::cin >> n;

    std::vector a(n, std::vector<int> (n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            std::cin >> a[i][j];
        }
    }

    int f = 0;
    while (f < 4) {
        int x[2] = {-1, -1}, y[2] = {-1, -1};
        for (int i = 2 * f; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                for (int k = 2 * f + 1; k < n; k++) {
                    if (a[2 * f][i] - a[2 * f][j] != a[k][i] - a[k][j]) {
                        x[0] = 2 * f;
                        x[1] = k;
                        y[0] = i;
                        y[1] = j;
                        break;
                    }
                }
                if (x[0] != -1) {
                    break;
                }
            }
            if (x[0] != -1) {
                break;
            }
        }

        if (x[0] == -1) {
            break;
        }
        if (x[1] != 2 * f + 1) {
            std::swap(a[x[1]], a[2 * f + 1]);
        }
        if (y[0] != 2 * f) {
            for (int i = 0; i < n; i++) {
                std::swap(a[i][y[0]], a[i][2 * f]);
            }
        }
        if (y[1] != 2 * f + 1) {
            for (int i = 0; i < n; i++) {
                std::swap(a[i][y[1]], a[i][2 * f + 1]);
            }
        }
        f++;
    }
    std::cerr << f << "\n";

    if (f == 4) {
        std::cout << "YYYYY\n";
        return 0;
    }

    int tr = 0;
    for (int i = 2 * f; i < n; i++) {
        int sub = a[2 * f][i];
        tr += sub;
        for (int j = 0; j < n; j++) {
            a[j][i] -= sub;
            a[j][i] = (a[j][i] + 5) % 5;
        }
    }
    for (int i = 2 * f; i < n; i++) {
        int sub = a[i][2 * f];
        tr += sub;
        for (int j = 0; j < n; j++) {
            a[i][j] -= sub;
            a[i][j] = (a[i][j] + 5) % 5;
        }
    }
    tr %= 5;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            std::cout << a[i][j] << " \n"[j == n - 1];
        }
    }

    const int F = 2 * f;

    int ans = 0;
    int usex = 0, usey = 0;
    auto dfs = [&](auto &&self, int x, int cur) -> void {
        if (x == F) {
            int res1 = 0, res2 = 0;
            {
                std::vector<int> f(1 << F);
                f[usey] = 1;

                for (int i = F; i < n; i++) {
                    auto g = f;
                    for (int u = 0; u < (1 << F); u++) {
                        for (int v = 0; v < F; v++) {
                            if (~u >> v & 1) {
                                int mask = f[u] * (1 << a[i][v]);
                                mask = mask % (1 << 5) | (mask / (1 << 5));
                                g[u | (1 << v)] |= mask;
                            }
                        }
                    }
                    f = std::move(g);
                }
                res1 = f[(1 << F) - 1];
            }
            {
                std::vector<int> f(1 << F);
                f[usex] = 1;

                for (int i = F; i < n; i++) {
                    auto g = f;
                    for (int u = 0; u < (1 << F); u++) {
                        for (int v = 0; v < F; v++) {
                            if (~u >> v & 1) {
                                int mask = f[u] * (1 << a[v][i]);
                                mask = mask % (1 << 5) | (mask / (1 << 5));
                                g[u | (1 << v)] |= mask;
                            }
                        }
                    }
                    f = std::move(g);
                }
                res2 = f[(1 << F) - 1];
            }
            for (int i = 0; i < 5; i++) {
                for (int j = 0; j < 5; j++) {
                    if ((res1 >> i & 1) && (res2 >> j & 1)) {
                        ans |= (1 << ((i + j + cur) % 5));
                    }
                }
            }
            return ;
        }
        self(self, x + 1, cur);
        for (int i = 0; i < F; i++) {
            if (~usey >> i & 1) {
                usex |= (1 << x);
                usey |= (1 << i);
                self(self, x + 1, (cur + a[x][i]) % 5);
                usex ^= (1 << x);
                usey ^= (1 << i);
            }
        }
    };
    dfs(dfs, 0, tr);

    for (int i = 0; i < 5; i++) {
        std::cout << ((ans >> i & 1) ? 'Y' : 'N');
    }
    std::cout << "\n";

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
0 4
4 0

output:

0 4
4 0
YNNYN

result:

wrong answer 1st words differ - expected: 'YNNYN', found: '0'