QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#789154#8830. Breaking Baducup-team004WA 0ms3824kbC++232.9kb2024-11-27 19:25:232024-11-27 19:25:24

Judging History

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

  • [2024-11-27 19:25:24]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3824kb
  • [2024-11-27 19:25:23]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = unsigned __int128;

int shift(int a, int k) {
    return a >> (5 - k) | a << k & 31;
}

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 k = 0;
    while (true) {
        if ([&]{
            for (int i = 2 * k; i < n; i++) {
                for (int j = 2 * k; j < n; j++) {
                    if ((a[2 * k][2 * k] + a[i][j]) % 5 != (a[2 * k][j] + a[i][2 * k]) % 5) {
                        std::swap(a[i], a[2 * k + 1]);
                        for (int r = 0; r < n; r++) {
                            std::swap(a[r][j], a[r][2 * k + 1]);
                        }
                        return true;
                    }
                }
            }
            return false;
        } ()) {
            k++;
            if (k >= 4) {
                std::cout << "YYYYY\n";
                return 0;
            }
        } else {
            break;
        }
    }
    
    k *= 2;
    
    int off = 0;
    for (int i = k; i < n; i++) {
        int v = a[i][k];
        off = (off + v) % 5;
        for (int j = 0; j < n; j++) {
            a[i][j] = (a[i][j] + 5 - off) % 5;
        }
    }
    for (int i = k; i < n; i++) {
        int v = a[k][i];
        off = (off + v) % 5;
        for (int j = 0; j < n; j++) {
            a[j][i] = (a[j][i] + 5 - off) % 5;
        }
    }
    std::vector<int> dp(1 << (2 * k));
    dp[0] = 1;
    
    for (int i = k; i < n; i++) {
        auto ndp = dp;
        for (int s = 0; s < (1 << (2 * k)); s++) {
            for (int j = 0; j < k; j++) {
                if (~s >> (k + j) & 1) {
                    ndp[s | 1 << (k + j)] |= shift(dp[s], a[i][j]);
                }
            }
        }
        dp = ndp;
    }
    for (int i = k; i < n; i++) {
        auto ndp = dp;
        for (int s = 0; s < (1 << (2 * k)); s++) {
            for (int j = 0; j < k; j++) {
                if (~s >> j & 1) {
                    ndp[s | 1 << j] |= shift(dp[s], a[j][i]);
                }
            }
        }
        dp = ndp;
    }
    
    for (int s = 0; s < (1 << (2 * k)); s++) {
        for (int i = 0; i < k; i++) {
            for (int j = 0; j < k; j++) {
                if ((~s >> i & 1) && (~s >> (k + j) & 1)) {
                    dp[s | 1 << i | 1 << (k + j)] |= shift(dp[s], a[i][j]);
                }
            }
        }
    }
    
    int ans = shift(dp.back(), off);
    for (int i = 0; i < 5; i++) {
        std::cout << "NY"[ans >> i & 1];
    }
    std::cout << "\n";
    
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3548kb

input:

2
0 4
4 0

output:

YNNYN

result:

ok "YNNYN"

Test #2:

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

input:

2
1 1
1 1

output:

NNYNN

result:

ok "NNYNN"

Test #3:

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

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: 3824kb

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: -100
Wrong Answer
time: 0ms
memory: 3548kb

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:

YYYYY

result:

wrong answer 1st words differ - expected: 'NYNNY', found: 'YYYYY'