QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#866040#8830. Breaking BadMisty7TL 1ms3712kbC++204.4kb2025-01-22 11:06:542025-01-22 11:06:55

Judging History

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

  • [2025-01-22 11:06:55]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3712kb
  • [2025-01-22 11:06:54]
  • 提交

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] + 5) % 5 != (a[k][i] - a[k][j] + 5) % 5) {
                        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::cout << x[0] << " " << x[1] << " " << y[0] << " " << y[1] << "\n";
        // for (int i = 0; i < n; i++) {
        //     for (int j = 0; j < n; j++) {
        //         std::cout << a[i][j] << " \n"[j == n - 1];
        //     }
        // }
        // std::cout << "\n";
    }
    // 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;

    const int F = 2 * f;

    std::vector<int> af(1 << F);
    af[0] = 1;

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

    std::vector<int> bf(1 << F);
    bf[0] = 1;

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

    int ans = 0;
    int usex = 0, usey = 0;
    auto dfs = [&](auto &&self, int x, int cur) -> void {
        if (x == F) {
            int res1 = af[((1 << F) - 1) ^ usey];
            int res2 = bf[((1 << F) - 1) ^ usex];
            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: 100
Accepted
time: 1ms
memory: 3712kb

input:

2
0 4
4 0

output:

YNNYN

result:

ok "YNNYN"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

2
1 1
1 1

output:

NNYNN

result:

ok "NNYNN"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

4
0 0 1 0
0 1 0 1
0 0 0 0
1 1 0 0

output:

YYYYN

result:

ok "YYYYN"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

4
0 0 0 1
0 1 0 1
1 0 0 0
0 1 0 0

output:

YYYYN

result:

ok "YYYYN"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

10
1 4 2 0 0 2 0 1 3 3
0 3 1 4 4 1 4 0 2 2
1 4 2 0 0 2 0 1 0 3
0 3 1 4 4 1 4 0 2 2
4 2 0 3 3 0 3 4 1 1
2 0 3 1 1 3 1 2 4 4
4 2 0 3 3 0 3 4 1 1
2 0 3 1 1 3 1 2 4 4
1 4 2 0 0 2 0 1 3 3
3 1 4 2 2 4 2 3 0 0

output:

NYNNY

result:

ok "NYNNY"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

10
4 4 4 1 3 4 1 4 3 0
3 3 3 0 2 3 0 3 2 4
3 3 3 0 2 3 0 3 2 4
4 4 4 1 3 4 1 4 3 0
2 2 2 4 1 2 4 2 1 3
2 2 2 4 1 3 4 2 1 3
4 4 4 1 3 4 1 4 3 0
3 3 3 0 2 3 0 3 2 4
2 2 2 4 1 2 4 2 1 3
4 4 4 1 3 4 1 1 3 0

output:

YYYNY

result:

ok "YYYNY"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

10
1 2 0 4 2 3 4 0 2 3
0 1 4 3 1 2 3 4 1 2
4 0 3 2 0 1 2 3 0 1
1 2 0 4 2 3 4 0 2 3
3 4 2 1 4 0 1 2 4 0
0 1 4 3 1 2 3 4 1 2
2 3 1 0 3 4 0 1 3 4
3 1 1 1 4 0 1 2 4 0
1 2 0 4 2 3 4 0 2 3
1 3 0 4 2 3 4 0 2 3

output:

NYYYY

result:

ok "NYYYY"

Test #8:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

10
3 4 0 3 2 2 0 4 0 2
0 1 2 0 4 4 2 1 2 4
2 3 4 2 1 1 4 3 4 1
0 1 2 0 4 4 2 1 2 4
0 1 2 0 4 4 2 1 2 4
0 1 2 0 4 4 2 1 2 4
3 4 0 3 2 2 0 4 0 2
0 1 2 0 4 4 2 1 2 4
3 4 0 3 2 2 0 4 0 2
0 1 2 0 4 4 2 1 2 4

output:

NYNNN

result:

ok "NYNNN"

Test #9:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

10
4 1 3 1 2 0 3 2 4 4
0 2 4 2 3 1 4 3 0 0
1 1 1 1 2 0 3 2 4 1
2 4 1 4 0 3 1 0 2 2
1 3 0 3 4 2 0 4 1 1
2 4 1 4 0 3 1 0 2 2
2 4 1 4 0 3 1 0 2 2
0 2 4 2 3 1 4 3 0 0
3 0 2 1 1 4 2 1 3 3
4 1 3 1 2 0 3 2 4 4

output:

YYYYY

result:

ok "YYYYY"

Test #10:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

10
1 2 0 2 4 2 3 1 2 1
4 0 3 0 2 0 1 4 0 4
0 1 4 1 3 1 2 0 1 0
0 1 4 1 3 1 2 0 1 0
3 4 2 4 1 4 0 3 4 3
4 0 3 0 2 0 1 4 0 4
0 1 4 1 3 1 2 0 1 0
0 1 4 1 3 1 2 0 1 0
3 4 2 4 1 4 0 3 4 3
0 1 4 1 3 1 2 0 1 0

output:

NNNYN

result:

ok "NNNYN"

Test #11:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

10
1 4 1 2 1 3 3 2 1 2
0 3 0 1 0 2 2 1 0 1
0 4 0 3 0 2 2 1 0 1
1 4 1 2 1 3 3 2 1 2
4 2 4 0 4 1 1 0 4 0
1 1 1 4 1 0 3 2 1 2
0 0 0 1 0 2 2 1 0 1
2 0 2 3 2 4 4 3 2 3
2 0 2 3 2 4 4 3 2 3
2 0 2 3 2 4 4 3 2 3

output:

YYYYY

result:

ok "YYYYY"

Test #12:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

10
1 2 0 1 4 0 1 2 2 2
1 2 0 1 4 3 1 2 2 2
0 1 4 0 3 1 0 1 1 1
1 2 0 1 4 3 1 2 2 2
3 4 2 3 1 4 3 4 4 4
0 1 4 0 3 1 0 1 1 1
4 0 3 4 2 0 4 0 0 0
3 4 2 3 1 4 3 4 4 4
4 0 3 4 2 0 4 0 0 0
0 1 4 0 3 1 0 1 1 1

output:

YNYNY

result:

ok "YNYNY"

Test #13:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

10
1 3 0 0 2 1 3 4 3 3
3 3 0 0 4 1 3 4 3 3
1 1 3 3 2 4 1 2 1 1
2 4 1 1 3 2 4 0 4 4
4 1 3 3 0 4 1 2 1 1
2 4 1 1 3 2 4 0 4 4
0 2 4 4 1 0 2 3 2 2
3 0 2 2 4 3 0 1 0 0
3 0 2 2 4 3 0 1 0 0
4 2 4 4 1 0 2 3 2 2

output:

YYYNY

result:

ok "YYYNY"

Test #14:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

10
2 0 3 1 3 0 0 0 4 1
1 4 2 0 2 4 4 4 3 0
2 0 3 1 3 0 0 0 4 1
1 4 2 0 2 4 4 4 3 0
1 4 2 0 2 4 4 4 3 0
3 3 4 2 4 1 1 1 0 2
3 1 4 2 4 1 1 1 0 2
4 2 0 3 0 2 2 2 1 3
3 1 4 2 4 1 1 1 0 2
1 4 2 0 2 4 4 4 3 0

output:

YNYNN

result:

ok "YNYNN"

Test #15:

score: -100
Time Limit Exceeded

input:

1000
3 4 1 2 4 1 0 3 0 4 1 4 3 1 4 4 1 0 1 2 3 1 0 1 3 4 4 0 3 0 3 2 2 1 0 4 1 3 3 0 3 1 3 2 2 0 3 3 2 2 3 0 4 2 1 2 1 2 1 4 2 4 1 4 2 4 3 2 0 3 0 4 2 1 2 3 3 0 2 0 3 3 1 1 0 3 4 3 2 0 4 0 3 4 4 2 3 4 2 3 4 2 1 3 2 2 4 1 0 2 2 4 0 1 2 0 4 1 3 2 3 2 2 2 1 4 4 4 2 0 0 4 4 1 3 4 0 2 2 3 1 1 3 2 3 2 3 0...

output:

NNNYN

result: