QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#789139 | #8830. Breaking Bad | ucup-team004 | WA | 0ms | 3660kb | C++23 | 2.9kb | 2024-11-27 19:23:03 | 2024-11-27 19:23:04 |
Judging History
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 << (n + 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: 3624kb
input:
2 0 4 4 0
output:
YNNYN
result:
ok "YNNYN"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
2 1 1 1 1
output:
NNYNN
result:
ok "NNYNN"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3660kb
input:
4 0 0 1 0 0 1 0 1 0 0 0 0 1 1 0 0
output:
NYNYN
result:
wrong answer 1st words differ - expected: 'YYYYN', found: 'NYNYN'