QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#866037 | #8830. Breaking Bad | Misty7 | TL | 1ms | 3712kb | C++20 | 4.8kb | 2025-01-22 11:01:43 | 2025-01-22 11:01:43 |
Judging History
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;
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: 100
Accepted
time: 0ms
memory: 3712kb
input:
2 0 4 4 0
output:
YNNYN
result:
ok "YNNYN"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
2 1 1 1 1
output:
NNYNN
result:
ok "NNYNN"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3584kb
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: 1ms
memory: 3712kb
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: 3712kb
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: 3584kb
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: 1ms
memory: 3584kb
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: 3712kb
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: 1ms
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: 1ms
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